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
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define FOR(a,b,c) for(int a=b, __c=c; a<=__c; ++a)
#define FORD(a,b,c) for(int a=b, __c=c; a>=__c; --a)
#define forv(a,b) for(auto &a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define fasty ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define gg exit(0);
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
const int N=2e5+5;
int n;
vector<int> ad[N];
int f[N],dd[N];
int ans=0;
void dfs(int u,int par){
int maxi=0;
forv(v,ad[u]) if(v!=par){
dfs(v,u);
f[u]+=f[v];
maxi=max(maxi,f[v]+1);
}
if(dd[u]){
ans=max(ans,maxi);
f[u]--;
f[u]=max(f[u],1ll);
}
ans=max(ans,f[u]);
}
int32_t main(){
fasty;
cin>>n;
FOR(i,1,n-1){
int u,v;
cin>>u>>v;
ad[u].pb(v); ad[v].pb(u);
}
FOR(i,1,n){
char x; cin>>x; dd[i]=x-'0';
}
dfs(1,0);
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... |