#include<bits/stdc++.h>
using namespace std;
const int MX = 200005;
vector<int>g[MX];
int n;
int dp[MX];
string s;
int solve(int v, int p=-1) {
int &ret = dp[v];
if(s[v]=='0') {
for(auto u : g[v]) if(u!=p) {
ret += solve(u, v);
}
} else {
int mx = 0;
for(auto u : g[v]) if(u!=p) {
mx = max(mx, solve(u, v));
}
if(mx<2) ret = mx+1;
else ret = mx;
}
return ret;
}
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;
cout << solve(1) << 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 |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Incorrect |
3 ms |
5016 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Incorrect |
3 ms |
5016 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Incorrect |
3 ms |
5016 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |