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;
typedef long long ll;
typedef vector<int> vi;
vector<vi> G;
string x;
int dfs(int u,int p){
int ans=0;
for(auto &v:G[u]){
if(v!=p){
ans+=dfs(v,u);
}
}
int mi=0;
if(x[u]=='1') mi=1;
return max(ans-mi,mi);
}
int main(){
int n;
cin>>n;
G.resize(n+1);
for(int i=0;i<n-1;i++){
int a,b; cin>>a>>b;
a--; b--;
G[a].push_back(b);
G[b].push_back(a);
}
cin>>x;
int ans=0;
for(int i=0;i<n;i++){
int rp=dfs(i,-1);
ans=max(ans,rp);
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |