Submission #423331

#TimeUsernameProblemLanguageResultExecution timeMemory
423331DanerZeinPower Plant (JOI20_power)C++14
0 / 100
1 ms292 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; vector<vi> G; string x; int dfs(int u,int p){ int ans=0; for(auto &v:G[u]){ if(v!=p){ ans+=dfs(v,u); } } int mi=0; if(x[u]=='1') mi=1; return max(ans-mi,mi); } int main(){ int n; cin>>n; G.resize(n+1); for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } cin>>x; int ans=0; for(int i=0;i<n;i++){ int rp=dfs(i,-1); ans=max(ans,rp); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...