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;
int n;
int x,y;
vector<int>a[300000];
int ktr[300000];
int f[300000];
string s;
int asw=0;
void sol(int i){
ktr[i]=1;
for(int u:a[i]){
if(!ktr[u]){
sol(u);
f[i]+=f[u];
}
}
if(s[i]=='1'&&f[i]<=1)f[i]++;
}
int main(){
cin >>n;
for(int i=1;i<n;i++){
cin >>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
cin >>s;
s=" "+s;
sol(1);
cout<<f[1];
}
/*
5 4
2 1 3
1 3 5 6
1 1 2 4
2 2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |