#include <bits/stdc++.h>
using namespace std;
const int lim = 2e5 + 5;
vector<int> edges[lim];
bool gen[lim], vis[lim];
int res[lim];
int ans = 0;
void dfs(int nd = 1) {
// ambil dr child, itu berarti boleh ambil dr semua di sum terus nanti dikurangi 1
// ambil dr skrg doang -> tergantung gen state
vis[nd] = 1;
int sum = 0, mx = 0;
for(auto i : edges[nd]) {
if(!vis[i]) {
dfs(i);
sum += res[i];
mx = max(mx, res[i]);
}
}
if(!gen[nd]) {
// then just merge aja :D
// berarti lgsg get sum from all
res[nd] = sum;
//cout << sum << endl;
}
else {
// kita harus rusak gen ini
// atau buat gen ini as root
// kalo buat gen as root, berarti choose 1 mx trus itu doang yg nyala
// else sum - 1
res[nd] = max(1, sum - 1);
ans = max(ans, mx + 1);
//cout << nd << " " << mx << " " << sum << endl;
}
}
int main() {
int n;
cin >> n;
for(int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
edges[u].push_back(v);
edges[v].push_back(u);
}
string s;
cin >> s;
for(int i = 1; i <= n; ++i)
gen[i] = s[i - 1] == '1';
dfs(1);
int mx = 0;
for(int i = 1; i <= n; ++i)
mx = max(res[i], mx);
cout << max(mx, ans) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5004 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5004 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5004 KB |
Output is correct |
22 |
Correct |
5 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5016 KB |
Output is correct |
25 |
Correct |
5 ms |
5020 KB |
Output is correct |
26 |
Correct |
5 ms |
5012 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
6 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
5 ms |
5204 KB |
Output is correct |
31 |
Correct |
5 ms |
5076 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5076 KB |
Output is correct |
37 |
Correct |
4 ms |
5076 KB |
Output is correct |
38 |
Correct |
5 ms |
5076 KB |
Output is correct |
39 |
Correct |
6 ms |
5076 KB |
Output is correct |
40 |
Correct |
4 ms |
5144 KB |
Output is correct |
41 |
Correct |
5 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5076 KB |
Output is correct |
44 |
Correct |
5 ms |
5144 KB |
Output is correct |
45 |
Correct |
4 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
5012 KB |
Output is correct |
48 |
Correct |
4 ms |
5176 KB |
Output is correct |
49 |
Correct |
4 ms |
5188 KB |
Output is correct |
50 |
Correct |
4 ms |
5148 KB |
Output is correct |
51 |
Correct |
4 ms |
5132 KB |
Output is correct |
52 |
Correct |
4 ms |
5076 KB |
Output is correct |
53 |
Correct |
6 ms |
5076 KB |
Output is correct |
54 |
Correct |
6 ms |
5080 KB |
Output is correct |
55 |
Correct |
5 ms |
5020 KB |
Output is correct |
56 |
Correct |
5 ms |
5076 KB |
Output is correct |
57 |
Correct |
5 ms |
5204 KB |
Output is correct |
58 |
Correct |
5 ms |
5076 KB |
Output is correct |
59 |
Correct |
5 ms |
5024 KB |
Output is correct |
60 |
Correct |
5 ms |
5076 KB |
Output is correct |
61 |
Correct |
5 ms |
5076 KB |
Output is correct |
62 |
Correct |
6 ms |
5204 KB |
Output is correct |
63 |
Correct |
5 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5004 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5004 KB |
Output is correct |
22 |
Correct |
5 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5016 KB |
Output is correct |
25 |
Correct |
5 ms |
5020 KB |
Output is correct |
26 |
Correct |
5 ms |
5012 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
6 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
5 ms |
5204 KB |
Output is correct |
31 |
Correct |
5 ms |
5076 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5076 KB |
Output is correct |
37 |
Correct |
4 ms |
5076 KB |
Output is correct |
38 |
Correct |
5 ms |
5076 KB |
Output is correct |
39 |
Correct |
6 ms |
5076 KB |
Output is correct |
40 |
Correct |
4 ms |
5144 KB |
Output is correct |
41 |
Correct |
5 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5076 KB |
Output is correct |
44 |
Correct |
5 ms |
5144 KB |
Output is correct |
45 |
Correct |
4 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
5012 KB |
Output is correct |
48 |
Correct |
4 ms |
5176 KB |
Output is correct |
49 |
Correct |
4 ms |
5188 KB |
Output is correct |
50 |
Correct |
4 ms |
5148 KB |
Output is correct |
51 |
Correct |
4 ms |
5132 KB |
Output is correct |
52 |
Correct |
4 ms |
5076 KB |
Output is correct |
53 |
Correct |
6 ms |
5076 KB |
Output is correct |
54 |
Correct |
6 ms |
5080 KB |
Output is correct |
55 |
Correct |
5 ms |
5020 KB |
Output is correct |
56 |
Correct |
5 ms |
5076 KB |
Output is correct |
57 |
Correct |
5 ms |
5204 KB |
Output is correct |
58 |
Correct |
5 ms |
5076 KB |
Output is correct |
59 |
Correct |
5 ms |
5024 KB |
Output is correct |
60 |
Correct |
5 ms |
5076 KB |
Output is correct |
61 |
Correct |
5 ms |
5076 KB |
Output is correct |
62 |
Correct |
6 ms |
5204 KB |
Output is correct |
63 |
Correct |
5 ms |
5076 KB |
Output is correct |
64 |
Correct |
218 ms |
15612 KB |
Output is correct |
65 |
Correct |
235 ms |
15560 KB |
Output is correct |
66 |
Correct |
226 ms |
15704 KB |
Output is correct |
67 |
Correct |
202 ms |
15584 KB |
Output is correct |
68 |
Correct |
221 ms |
15472 KB |
Output is correct |
69 |
Correct |
204 ms |
15576 KB |
Output is correct |
70 |
Correct |
210 ms |
15644 KB |
Output is correct |
71 |
Correct |
220 ms |
15468 KB |
Output is correct |
72 |
Correct |
199 ms |
15480 KB |
Output is correct |
73 |
Correct |
235 ms |
28188 KB |
Output is correct |
74 |
Correct |
233 ms |
28152 KB |
Output is correct |
75 |
Correct |
223 ms |
15468 KB |
Output is correct |
76 |
Correct |
188 ms |
15364 KB |
Output is correct |
77 |
Correct |
227 ms |
15456 KB |
Output is correct |
78 |
Correct |
222 ms |
15560 KB |
Output is correct |
79 |
Correct |
227 ms |
15356 KB |
Output is correct |
80 |
Correct |
205 ms |
15472 KB |
Output is correct |
81 |
Correct |
190 ms |
15820 KB |
Output is correct |
82 |
Correct |
189 ms |
15700 KB |
Output is correct |
83 |
Correct |
202 ms |
20688 KB |
Output is correct |
84 |
Correct |
196 ms |
22784 KB |
Output is correct |
85 |
Correct |
216 ms |
22544 KB |
Output is correct |
86 |
Correct |
205 ms |
16940 KB |
Output is correct |
87 |
Correct |
193 ms |
16372 KB |
Output is correct |
88 |
Correct |
231 ms |
16800 KB |
Output is correct |
89 |
Correct |
184 ms |
16720 KB |
Output is correct |
90 |
Correct |
210 ms |
16684 KB |
Output is correct |
91 |
Correct |
211 ms |
16720 KB |
Output is correct |
92 |
Correct |
189 ms |
17056 KB |
Output is correct |
93 |
Correct |
203 ms |
19492 KB |
Output is correct |
94 |
Correct |
181 ms |
21232 KB |
Output is correct |
95 |
Correct |
191 ms |
19872 KB |
Output is correct |
96 |
Correct |
184 ms |
18064 KB |
Output is correct |
97 |
Correct |
194 ms |
16552 KB |
Output is correct |
98 |
Correct |
221 ms |
16352 KB |
Output is correct |
99 |
Correct |
190 ms |
15896 KB |
Output is correct |
100 |
Correct |
194 ms |
19056 KB |
Output is correct |
101 |
Correct |
221 ms |
17084 KB |
Output is correct |
102 |
Correct |
174 ms |
16336 KB |
Output is correct |
103 |
Correct |
208 ms |
16124 KB |
Output is correct |
104 |
Correct |
165 ms |
16372 KB |
Output is correct |
105 |
Correct |
209 ms |
25008 KB |
Output is correct |
106 |
Correct |
169 ms |
16216 KB |
Output is correct |
107 |
Correct |
149 ms |
16184 KB |
Output is correct |
108 |
Correct |
217 ms |
29020 KB |
Output is correct |
109 |
Correct |
180 ms |
16372 KB |
Output is correct |
110 |
Correct |
240 ms |
29212 KB |
Output is correct |
111 |
Correct |
214 ms |
15392 KB |
Output is correct |