Submission #1058889

#TimeUsernameProblemLanguageResultExecution timeMemory
1058889YassirSalamaPower Plant (JOI20_power)C++17
100 / 100
119 ms26852 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define pb push_back #define all(v) v.begin(),v.end() const int maxn=2e5+100; string s; vector<int> v[maxn]; int dp[maxn]; int ans=0; void dfs(int node,int par){ if(s[node]=='1'){ for(auto x:v[node]){ if(x==par) continue; dfs(x,node); dp[node]+=dp[x]; ans=max(ans,dp[x]+1); } dp[node]--; dp[node]=max(dp[node],1LL); }else{ for(auto x:v[node]){ if(x==par) continue; dfs(x,node); dp[node]+=dp[x]; } } ans=max(ans,dp[node]); } signed main(){ int n; cin>>n; for(int i=1;i<n;i++){ int a,b; cin>>a>>b;a--,b--; v[a].pb(b); v[b].pb(a); } cin>>s; dfs(0,0); cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...