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[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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |