Submission #868649

#TimeUsernameProblemLanguageResultExecution timeMemory
86864912345678Power Plant (JOI20_power)C++17
100 / 100
99 ms29584 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e5+5; int n, u, v, dp1[nx], dp2[nx], ans; vector<int> d[nx]; string s; void dfs(int u, int p) { for (auto v:d[u]) { if (v==p) continue; dfs(v, u); if (s[u-1]=='1') dp1[u]+=dp1[v], dp2[u]=max(dp2[u], dp1[v]+1); else dp1[u]+=max(dp1[v], dp2[v]-2), dp2[u]=max(dp2[u], dp2[v]); } if (s[u-1]=='1') dp1[u]=max(1, dp1[u]-1), dp2[u]=max(dp2[u], 1); ans=max({ans, dp1[u], dp2[u]}); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u); cin>>s; dfs(1, 1); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...