Submission #882853

#TimeUsernameProblemLanguageResultExecution timeMemory
882853TomkeMonkePower Plant (JOI20_power)C++17
100 / 100
117 ms29704 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 7; vector<int> G[MAXN]; string s; int path[MAXN], siz[MAXN]; int ans = 0; void DFS(int v, int p){ int maks = 0, sum = 0; for(auto u : G[v]){ if(u == p) continue; DFS(u, v); sum += siz[u]; maks = max(maks, siz[u]); } if(s[v] == '1'){ path[v] = maks + 1; siz[v] = max(1, sum - 1); } else { path[v] = maks; siz[v] = sum; } ans = max(ans, max(path[v], siz[v])); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; 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 >> s; s = "#" + s; DFS(1, 1); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...