Submission #1299174

#TimeUsernameProblemLanguageResultExecution timeMemory
1299174khoile08Power Plant (JOI20_power)C++20
100 / 100
153 ms25940 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; i++) #define FOD(i, a, b) for(int i = a; i >= b; i--) //#define int long long #define fi first #define se second #define ll long long #define db double #define pb push_back #define ii pair<int,int> #define sq(i) (1LL * (i) * (i)) #define MASK(i) (1LL << i) #define task "task" const int inf = 1e9; const ll INF = 1e18; const int N = 2e5 + 4; int n, res; vector<int> g[N]; bool ch[N]; int dp[N]; void dfs(int u, int p) { for(int v : g[u]) { if(v == p) continue; dfs(v, u); dp[u] += dp[v]; res = max(res, dp[v] + ch[u]); } dp[u] -= ch[u]; dp[u] = max(dp[u], (int)ch[u]); } signed main() { if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; FOR(i, 1, n - 1) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } FOR(i, 1, n) { char c; cin >> c; ch[i] = (c == '1'); } dfs(1, -1); FOR(i, 1, n) res = max(res, dp[i]); cout << res << '\n'; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
power.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...