Submission #787681

#TimeUsernameProblemLanguageResultExecution timeMemory
787681winter0101Power Plant (JOI20_power)C++14
100 / 100
115 ms28836 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) #define pil pair<int,long long> vector<int>a[200009]; int f[200009]; string s; int ans=0; void dfs(int u,int par){ if (s[u]=='1'){ f[u]=1; } int sum=0; for (auto v:a[u]){ if (v==par)continue; dfs(v,u); if (s[u]=='1'){ ans=max(ans,f[v]+1); } sum+=f[v]; } if (s[u]=='1')sum--; f[u]=max(f[u],sum); ans=max(ans,f[u]); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen("temp.OUT","w",stdout); int n; cin>>n; for1(i,1,n-1){ int u,v; cin>>u>>v; a[u].pb(v); a[v].pb(u); } cin>>s; s=" "+s; dfs(1,0); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...