이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |