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;
const int MAXN=200005;
vector<int> adj[MAXN];
int lampu[MAXN],dp[MAXN],ans;
void dfs(int now,int par){
int maxi=0;
bool leaf=true;
for(auto nxt : adj[now]){
if(nxt==par)continue;
leaf=false;
dfs(nxt,now);
dp[now]+=dp[nxt];
maxi=max(maxi,dp[nxt]);
}
if(lampu[now]){
dp[now]--;
dp[now]=max(dp[now],1);
if(!leaf)ans=max(ans,maxi+1);
}
ans=max(ans,dp[now]);
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,u,v;
char a;
cin >> n;
for(int i=1;i<n;i++){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++){
cin >> a;
if(a=='1')lampu[i]=1;
}
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... |