#include<bits/stdc++.h>
using namespace std;
const int MX = 200005;
vector<int>g[MX];
int n;
int sub[MX];
string s;
int ans;
int DFS(int v, int p=0) {
int cnt = 0;
bool hierOn = false;
for(int u : g[v]) if(u!=p) {
int get = DFS(u, v);
if(get!=0) {
++cnt;
if(get==2) hierOn = 1;
}
}
if(hierOn==0 && cnt<2 && s[v]=='1') {
++ans;
if(cnt) sub[v] = 2;
else sub[v] = 1;
} else if(hierOn) {
sub[v] = 2;
} else {
sub[v] = cnt!=0;
}
return sub[v];
}
void PlayGround() {
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;
s = "#" + s;
DFS(1);
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |