Submission #453687

#TimeUsernameProblemLanguageResultExecution timeMemory
453687iulia13Power Plant (JOI20_power)C++14
100 / 100
318 ms31464 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector <int> g[N]; int dp[N], n; char a[N]; int dfs(int nod, int dad) { int st = a[nod] - '0', bst_son = 0, bst = 0; for (auto x : g[nod]) { if (x == dad) continue; bst = max(bst, dfs(x, nod)); dp[nod] += dp[x]; bst_son = max(bst_son, dp[x]); } dp[nod] = max(st, dp[nod] - st); ///a or b... return max(bst, max(dp[nod], bst_son + st)); } int main() { cin >> n; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } cin >> a + 1; cout << dfs(1, 0); return 0; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:32:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     cin >> a + 1;
      |            ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...