Submission #803448

#TimeUsernameProblemLanguageResultExecution timeMemory
803448khoquennguoiminhthuongPower Plant (JOI20_power)C++14
100 / 100
142 ms26156 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int>g[200005]; string s; int a[200005]; int dp[200005]; int ans=0; void dfs(int u,int pa) { dp[u]=a[u]; int sum1=0,sum2=0; for(auto v:g[u]) if(v!=pa) { dfs(v,u); sum1=max(sum1,dp[v]); sum2+=dp[v]; } ans=max(ans,sum1+a[u]); dp[u]=max(dp[u],sum2-a[u]); ans=max(ans,dp[u]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i=1; i<n; i++) { int u,v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } cin>>s; for(int i=0; i<n; i++)if(s[i]=='1')a[i+1]=1; dfs(1,0); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...