Submission #568057

#TimeUsernameProblemLanguageResultExecution timeMemory
568057fadi57Power Plant (JOI20_power)C++14
47 / 100
1578 ms15988 KiB
#include<bits/stdc++.h> using namespace std; const int mx=2e5+5; vector<int>adj[mx]; int mark[mx]; int ans; int dp[mx]; void dfs(int node,int par){ int sum=0; int maxi=0; for(auto it:adj[node]){ if(it!=par){ dfs(it,node); sum+=dp[it]; maxi=max(maxi,dp[it]); } } if(node==par){ ans=max(maxi+1,ans); } if(mark[node]){ dp[node]=max(sum-1,1); }else{ dp[node]=sum; } ans=max(ans,dp[node]); } int main(){ int n;cin>>n; for(int i=0;i<n-1;i++){ int x,y; cin>>x>>y; x--;y--; adj[x].push_back(y); adj[y].push_back(x); } string x;cin>>x; for(int i=0;i<n;i++){ mark[i]=(x[i]=='1'); } for(int i=0;i<n;i++){ if(mark[i]){ dfs(i,i); } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...