Submission #399950

#TimeUsernameProblemLanguageResultExecution timeMemory
399950nikatamlianiPower Plant (JOI20_power)C++14
0 / 100
4 ms5072 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5+10; vector<int> edges[N]; int dp[N], ans, n; string s; void solve(int x, int p) { int sum = 0, maxi = 0; for(int to : edges[x]) { if(to != p) { solve(to, x); sum += dp[to]; maxi = max(maxi, dp[to]); } } if(s[x] == '1') { dp[x] = max(sum-1, 1); ans = max(ans, maxi+1); } else { dp[x] = sum; } ans = max(ans, sum); ans = max(ans, dp[x]); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 0; i < n-1; ++i) { int u, v; cin >> u >> v; edges[u].push_back(v); edges[v].push_back(u); } cin >> s; s = "@" + s; solve(1, 0); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...