#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;
DFS(u, v);
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6644 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6544 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
2 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6488 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6548 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6644 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6544 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
2 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6488 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6548 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6560 KB |
Output is correct |
26 |
Correct |
2 ms |
6488 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
3 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6492 KB |
Output is correct |
34 |
Correct |
2 ms |
6492 KB |
Output is correct |
35 |
Correct |
2 ms |
6504 KB |
Output is correct |
36 |
Correct |
3 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
3 ms |
6556 KB |
Output is correct |
39 |
Correct |
2 ms |
6756 KB |
Output is correct |
40 |
Correct |
2 ms |
6492 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6576 KB |
Output is correct |
43 |
Correct |
2 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6564 KB |
Output is correct |
47 |
Correct |
3 ms |
6492 KB |
Output is correct |
48 |
Correct |
4 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6744 KB |
Output is correct |
50 |
Correct |
3 ms |
6492 KB |
Output is correct |
51 |
Correct |
2 ms |
6744 KB |
Output is correct |
52 |
Correct |
2 ms |
6492 KB |
Output is correct |
53 |
Correct |
2 ms |
6488 KB |
Output is correct |
54 |
Correct |
3 ms |
6492 KB |
Output is correct |
55 |
Correct |
3 ms |
6492 KB |
Output is correct |
56 |
Correct |
2 ms |
6492 KB |
Output is correct |
57 |
Correct |
3 ms |
6732 KB |
Output is correct |
58 |
Correct |
2 ms |
6492 KB |
Output is correct |
59 |
Correct |
2 ms |
6492 KB |
Output is correct |
60 |
Correct |
2 ms |
6492 KB |
Output is correct |
61 |
Correct |
2 ms |
6560 KB |
Output is correct |
62 |
Correct |
3 ms |
7000 KB |
Output is correct |
63 |
Correct |
2 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6644 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6544 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
2 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6488 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6548 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6560 KB |
Output is correct |
26 |
Correct |
2 ms |
6488 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
3 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6492 KB |
Output is correct |
34 |
Correct |
2 ms |
6492 KB |
Output is correct |
35 |
Correct |
2 ms |
6504 KB |
Output is correct |
36 |
Correct |
3 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
3 ms |
6556 KB |
Output is correct |
39 |
Correct |
2 ms |
6756 KB |
Output is correct |
40 |
Correct |
2 ms |
6492 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6576 KB |
Output is correct |
43 |
Correct |
2 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6564 KB |
Output is correct |
47 |
Correct |
3 ms |
6492 KB |
Output is correct |
48 |
Correct |
4 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6744 KB |
Output is correct |
50 |
Correct |
3 ms |
6492 KB |
Output is correct |
51 |
Correct |
2 ms |
6744 KB |
Output is correct |
52 |
Correct |
2 ms |
6492 KB |
Output is correct |
53 |
Correct |
2 ms |
6488 KB |
Output is correct |
54 |
Correct |
3 ms |
6492 KB |
Output is correct |
55 |
Correct |
3 ms |
6492 KB |
Output is correct |
56 |
Correct |
2 ms |
6492 KB |
Output is correct |
57 |
Correct |
3 ms |
6732 KB |
Output is correct |
58 |
Correct |
2 ms |
6492 KB |
Output is correct |
59 |
Correct |
2 ms |
6492 KB |
Output is correct |
60 |
Correct |
2 ms |
6492 KB |
Output is correct |
61 |
Correct |
2 ms |
6560 KB |
Output is correct |
62 |
Correct |
3 ms |
7000 KB |
Output is correct |
63 |
Correct |
2 ms |
6488 KB |
Output is correct |
64 |
Correct |
86 ms |
16064 KB |
Output is correct |
65 |
Correct |
61 ms |
16040 KB |
Output is correct |
66 |
Correct |
61 ms |
16056 KB |
Output is correct |
67 |
Correct |
82 ms |
15996 KB |
Output is correct |
68 |
Correct |
99 ms |
16344 KB |
Output is correct |
69 |
Correct |
85 ms |
16112 KB |
Output is correct |
70 |
Correct |
66 ms |
16096 KB |
Output is correct |
71 |
Correct |
80 ms |
16024 KB |
Output is correct |
72 |
Correct |
72 ms |
16208 KB |
Output is correct |
73 |
Correct |
92 ms |
28624 KB |
Output is correct |
74 |
Correct |
104 ms |
28616 KB |
Output is correct |
75 |
Correct |
80 ms |
15980 KB |
Output is correct |
76 |
Correct |
64 ms |
16024 KB |
Output is correct |
77 |
Correct |
114 ms |
15916 KB |
Output is correct |
78 |
Correct |
105 ms |
15948 KB |
Output is correct |
79 |
Correct |
78 ms |
16028 KB |
Output is correct |
80 |
Correct |
62 ms |
15952 KB |
Output is correct |
81 |
Correct |
60 ms |
16272 KB |
Output is correct |
82 |
Correct |
77 ms |
16184 KB |
Output is correct |
83 |
Correct |
73 ms |
20988 KB |
Output is correct |
84 |
Correct |
76 ms |
23260 KB |
Output is correct |
85 |
Correct |
85 ms |
22800 KB |
Output is correct |
86 |
Correct |
72 ms |
17416 KB |
Output is correct |
87 |
Correct |
64 ms |
16840 KB |
Output is correct |
88 |
Correct |
105 ms |
17112 KB |
Output is correct |
89 |
Correct |
62 ms |
17180 KB |
Output is correct |
90 |
Correct |
92 ms |
16928 KB |
Output is correct |
91 |
Correct |
89 ms |
17136 KB |
Output is correct |
92 |
Correct |
88 ms |
17592 KB |
Output is correct |
93 |
Correct |
79 ms |
19944 KB |
Output is correct |
94 |
Correct |
75 ms |
21704 KB |
Output is correct |
95 |
Correct |
67 ms |
20356 KB |
Output is correct |
96 |
Correct |
73 ms |
18488 KB |
Output is correct |
97 |
Correct |
67 ms |
17116 KB |
Output is correct |
98 |
Correct |
91 ms |
16664 KB |
Output is correct |
99 |
Correct |
81 ms |
16428 KB |
Output is correct |
100 |
Correct |
83 ms |
19516 KB |
Output is correct |
101 |
Correct |
70 ms |
17492 KB |
Output is correct |
102 |
Correct |
81 ms |
16800 KB |
Output is correct |
103 |
Correct |
95 ms |
16564 KB |
Output is correct |
104 |
Correct |
49 ms |
16832 KB |
Output is correct |
105 |
Correct |
79 ms |
25344 KB |
Output is correct |
106 |
Correct |
45 ms |
16768 KB |
Output is correct |
107 |
Correct |
40 ms |
16848 KB |
Output is correct |
108 |
Correct |
81 ms |
29324 KB |
Output is correct |
109 |
Correct |
41 ms |
16908 KB |
Output is correct |
110 |
Correct |
117 ms |
29704 KB |
Output is correct |
111 |
Correct |
74 ms |
15992 KB |
Output is correct |