#include <bits/stdc++.h>
using namespace std;
const int N = (int) 2e5 + 7;
int n, sub[N], total, best;
vector<int> g[N];
string s;
void build(int a, int p = -1) {
int cnt = -sub[a];
for (auto &b : g[a]) {
if (b == p) {
continue;
}
build(b, a);
cnt += (sub[b] > 0);
sub[a] += sub[b];
}
cnt += (sub[a] < total);
best = max(best, cnt);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
cin >> s;
for (int i = 1; i <= n; i++) {
sub[i] = s[i - 1] - '0';
total += sub[i];
}
best = (total > 0);
build(1);
cout << best << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4944 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4944 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4944 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |