Submission #868650

#TimeUsernameProblemLanguageResultExecution timeMemory
86865012345678Power Plant (JOI20_power)C++17
0 / 100
1 ms4956 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e5+5; int n, u, v, dp1[nx], dp2[nx]; 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); } 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<<max({dp1[1], dp2[1], 0}); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...