This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |