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>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=2e5+5;
int n, dp[N], pd[N];
vector<int>g[N];
string s;
void dfs(const int &v, const int &p=-1){
for(int u: g[v]){
if(u!=p){
dfs(u, v);
pd[v]+=pd[u];
if(s[v]=='1')
dp[v]=max(dp[v], pd[u]+1);
dp[v]=max(dp[v], dp[u]);
}
}
if(s[v]=='1'){
--pd[v];
pd[v]=max(pd[v], 1);
}
dp[v]=max(dp[v], pd[v]);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1;i<n;++i){
int u, v;
cin>>u>>v;
g[--u].push_back(--v);
g[v].push_back(u);
}
cin>>s;
dfs(0);
cout<<dp[0]<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |