Submission #516321

#TimeUsernameProblemLanguageResultExecution timeMemory
516321jk410Power Plant (JOI20_power)C++17
100 / 100
149 ms29552 KiB
#include <bits/stdc++.h> using namespace std; int N,Ans; int A[200001],DP[200001]; string S; vector<int> Edge[200001]; void dfs(int v,int par=0){ int sum=0,mx=0; for (int i:Edge[v]){ if (i==par) continue; dfs(i,v); sum+=DP[i]; mx=max(mx,DP[i]); } DP[v]=max(sum-A[v],A[v]); Ans=max({Ans,sum-A[v],mx+A[v]}); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>N; for (int i=1,a,b; i<N; i++){ cin>>a>>b; Edge[a].push_back(b); Edge[b].push_back(a); } cin>>S; for (int i=1; i<=N; i++) A[i]=(S[i-1]-'0'); dfs(1); cout<<Ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...