Submission #293488

#TimeUsernameProblemLanguageResultExecution timeMemory
293488nandonathanielPower Plant (JOI20_power)C++14
100 / 100
203 ms25976 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=200005; vector<int> adj[MAXN]; int lampu[MAXN],dp[MAXN],ans; void dfs(int now,int par){ int maxi=0; bool leaf=true; for(auto nxt : adj[now]){ if(nxt==par)continue; leaf=false; dfs(nxt,now); dp[now]+=dp[nxt]; maxi=max(maxi,dp[nxt]); } if(lampu[now]){ dp[now]--; dp[now]=max(dp[now],1); if(!leaf)ans=max(ans,maxi+1); } ans=max(ans,dp[now]); } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n,u,v; char a; cin >> n; for(int i=1;i<n;i++){ cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for(int i=1;i<=n;i++){ cin >> a; if(a=='1')lampu[i]=1; } 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...