Submission #507659

#TimeUsernameProblemLanguageResultExecution timeMemory
507659nichkePower Plant (JOI20_power)C++14
100 / 100
155 ms29696 KiB
// I may fail a thousand times // But there is no giving up // IOI - here I come #include <bits/stdc++.h> #define pb push_back #define int long long using namespace std; int ans; string s; int dp[(int)2e5+5]; vector<int> g[(int)2e5+5]; int dfs(int v,int p){ for(int u:g[v]){ if(u==p)continue; dp[v]+=dfs(u,v); ans=max(ans,dp[u]+(s[v-1]=='1')); } dp[v]-=s[v-1]=='1'; dp[v]=max(dp[v],(int)(s[v-1]=='1')); ans=max(ans,dp[v]); return dp[v]; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n; for(int i=1,u,v;i<n;i++)cin>>u>>v,g[u].pb(v),g[v].pb(u); cin>>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...