#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
vector<int> G[MAXN];
string s;
int path[MAXN], siz[MAXN];
int ans = 0;
void DFS(int v, int p){
int maks = 0, sum = 0;
for(auto u : G[v]){
if(u == p) continue;
sum += siz[u];
maks = max(maks, siz[u]);
}
if(s[v] == '1'){
path[v] = maks + 1;
siz[v] = max(1, sum - 1);
}
else {
path[v] = maks;
siz[v] = sum;
}
ans = max(ans, max(path[v], siz[v]));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
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;
s = "#" + s;
DFS(1, 1);
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
6544 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
6544 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
6544 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |