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;
#define int long long
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const int maxn=2e5+100;
string s;
vector<int> v[maxn];
int dp[maxn];
int ans=0;
void dfs(int node,int par){
if(s[node]=='1'){
for(auto x:v[node]){
if(x==par) continue;
dfs(x,node);
dp[node]+=dp[x];
ans=max(ans,dp[x]+1);
}
dp[node]--;
dp[node]=max(dp[node],1LL);
}else{
for(auto x:v[node]){
if(x==par) continue;
dfs(x,node);
dp[node]+=dp[x];
}
}
ans=max(ans,dp[node]);
}
signed main(){
int n;
cin>>n;
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;a--,b--;
v[a].pb(b);
v[b].pb(a);
}
cin>>s;
dfs(0,0);
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... |