This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I may fail a thousand times
// But there is no giving up
// IOI - here I come
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
int ans;
string s;
int dp[(int)2e5+5];
vector<int> g[(int)2e5+5];
int dfs(int v,int p){
for(int u:g[v]){
if(u==p)continue;
dp[v]+=dfs(u,v);
ans=max(ans,dp[u]+(s[v-1]=='1'));
}
dp[v]-=s[v-1]=='1';
dp[v]=max(dp[v],(int)(s[v-1]=='1'));
ans=max(ans,dp[v]);
return dp[v];
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
for(int i=1,u,v;i<n;i++)cin>>u>>v,g[u].pb(v),g[v].pb(u);
cin>>s;
dfs(1,1);
cout<<ans<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |