Submission #516312

#TimeUsernameProblemLanguageResultExecution timeMemory
516312jk410Power Plant (JOI20_power)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; int N,Ans; int A[2001],DP[2001]; string S; vector<int> Edge[2001]; int dfs(int v,int par=0){ DP[v]=-A[v]; for (int i:Edge[v]){ if (i==par) continue; DP[v]+=dfs(i,v); } DP[v]=max(DP[v],A[v]); return DP[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'); for (int i=1; i<=N; i++) Ans=max(Ans,dfs(i)); cout<<Ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...