#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (a); (i) < (n); ++(i))
using namespace std;
const int N = 2e5 + 50;
int n;
vector<int> graph[N];
string s;
int dp[N];
int sol = 0;
int rek(int v, int p) {
int sum = 0, mx = 0, cnt = 0;
for(auto n : graph[v]) {
if(n == p) continue;
int val = rek(n, v);
if(val) cnt++;
sum += val;
mx = max(mx, val);
}
//if(s[v] == '0' || cnt > 1) dp[v] = max(s[v] - '0', sum - s[v] + '0');
//else dp[v] = max(1, sum);
dp[v] = max(s[v] - '0', sum - (s[v] - '0'));
if(s[v] == '1') {
sol = max(sol, max(mx + 1, dp[v]));
} else {
sol = max(sol, dp[v]);
}
return dp[v];
}
int main() {
cin >> n;
rep(i, 0, n - 1) {
int a, b;
cin >> a >> b;
--a, --b;
graph[a].push_back(b);
graph[b].push_back(a);
}
cin >> s;
rek(0, -1);
printf("%d\n", sol);
return 0;
}
Compilation message
power.cpp: In function 'int main()':
power.cpp:3:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
3 | #define rep(i, a, n) for(int (i) = (a); (i) < (n); ++(i))
| ^
power.cpp:41:9: note: in expansion of macro 'rep'
41 | rep(i, 0, n - 1) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
5024 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
4968 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
5024 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
4968 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
6 ms |
5120 KB |
Output is correct |
23 |
Correct |
6 ms |
5120 KB |
Output is correct |
24 |
Correct |
7 ms |
5248 KB |
Output is correct |
25 |
Correct |
6 ms |
5120 KB |
Output is correct |
26 |
Correct |
6 ms |
5120 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5248 KB |
Output is correct |
30 |
Correct |
6 ms |
5248 KB |
Output is correct |
31 |
Correct |
6 ms |
5120 KB |
Output is correct |
32 |
Correct |
6 ms |
5120 KB |
Output is correct |
33 |
Correct |
7 ms |
5120 KB |
Output is correct |
34 |
Correct |
6 ms |
5120 KB |
Output is correct |
35 |
Correct |
6 ms |
5120 KB |
Output is correct |
36 |
Correct |
7 ms |
5120 KB |
Output is correct |
37 |
Correct |
6 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 ms |
5120 KB |
Output is correct |
39 |
Correct |
7 ms |
5120 KB |
Output is correct |
40 |
Correct |
6 ms |
5120 KB |
Output is correct |
41 |
Correct |
6 ms |
5120 KB |
Output is correct |
42 |
Correct |
6 ms |
5120 KB |
Output is correct |
43 |
Correct |
6 ms |
5120 KB |
Output is correct |
44 |
Correct |
6 ms |
5120 KB |
Output is correct |
45 |
Correct |
6 ms |
5120 KB |
Output is correct |
46 |
Correct |
6 ms |
5120 KB |
Output is correct |
47 |
Correct |
6 ms |
5120 KB |
Output is correct |
48 |
Correct |
6 ms |
5248 KB |
Output is correct |
49 |
Correct |
7 ms |
5216 KB |
Output is correct |
50 |
Correct |
6 ms |
5120 KB |
Output is correct |
51 |
Correct |
6 ms |
5120 KB |
Output is correct |
52 |
Correct |
6 ms |
5120 KB |
Output is correct |
53 |
Correct |
6 ms |
5120 KB |
Output is correct |
54 |
Correct |
6 ms |
5120 KB |
Output is correct |
55 |
Correct |
6 ms |
5120 KB |
Output is correct |
56 |
Correct |
6 ms |
5120 KB |
Output is correct |
57 |
Correct |
6 ms |
5248 KB |
Output is correct |
58 |
Correct |
6 ms |
5120 KB |
Output is correct |
59 |
Correct |
6 ms |
5120 KB |
Output is correct |
60 |
Correct |
6 ms |
5248 KB |
Output is correct |
61 |
Correct |
6 ms |
5120 KB |
Output is correct |
62 |
Correct |
6 ms |
5248 KB |
Output is correct |
63 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
5024 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
4968 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
6 ms |
5120 KB |
Output is correct |
23 |
Correct |
6 ms |
5120 KB |
Output is correct |
24 |
Correct |
7 ms |
5248 KB |
Output is correct |
25 |
Correct |
6 ms |
5120 KB |
Output is correct |
26 |
Correct |
6 ms |
5120 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5248 KB |
Output is correct |
30 |
Correct |
6 ms |
5248 KB |
Output is correct |
31 |
Correct |
6 ms |
5120 KB |
Output is correct |
32 |
Correct |
6 ms |
5120 KB |
Output is correct |
33 |
Correct |
7 ms |
5120 KB |
Output is correct |
34 |
Correct |
6 ms |
5120 KB |
Output is correct |
35 |
Correct |
6 ms |
5120 KB |
Output is correct |
36 |
Correct |
7 ms |
5120 KB |
Output is correct |
37 |
Correct |
6 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 ms |
5120 KB |
Output is correct |
39 |
Correct |
7 ms |
5120 KB |
Output is correct |
40 |
Correct |
6 ms |
5120 KB |
Output is correct |
41 |
Correct |
6 ms |
5120 KB |
Output is correct |
42 |
Correct |
6 ms |
5120 KB |
Output is correct |
43 |
Correct |
6 ms |
5120 KB |
Output is correct |
44 |
Correct |
6 ms |
5120 KB |
Output is correct |
45 |
Correct |
6 ms |
5120 KB |
Output is correct |
46 |
Correct |
6 ms |
5120 KB |
Output is correct |
47 |
Correct |
6 ms |
5120 KB |
Output is correct |
48 |
Correct |
6 ms |
5248 KB |
Output is correct |
49 |
Correct |
7 ms |
5216 KB |
Output is correct |
50 |
Correct |
6 ms |
5120 KB |
Output is correct |
51 |
Correct |
6 ms |
5120 KB |
Output is correct |
52 |
Correct |
6 ms |
5120 KB |
Output is correct |
53 |
Correct |
6 ms |
5120 KB |
Output is correct |
54 |
Correct |
6 ms |
5120 KB |
Output is correct |
55 |
Correct |
6 ms |
5120 KB |
Output is correct |
56 |
Correct |
6 ms |
5120 KB |
Output is correct |
57 |
Correct |
6 ms |
5248 KB |
Output is correct |
58 |
Correct |
6 ms |
5120 KB |
Output is correct |
59 |
Correct |
6 ms |
5120 KB |
Output is correct |
60 |
Correct |
6 ms |
5248 KB |
Output is correct |
61 |
Correct |
6 ms |
5120 KB |
Output is correct |
62 |
Correct |
6 ms |
5248 KB |
Output is correct |
63 |
Correct |
6 ms |
5120 KB |
Output is correct |
64 |
Correct |
377 ms |
15260 KB |
Output is correct |
65 |
Correct |
370 ms |
15240 KB |
Output is correct |
66 |
Correct |
374 ms |
15400 KB |
Output is correct |
67 |
Correct |
369 ms |
15240 KB |
Output is correct |
68 |
Correct |
372 ms |
15152 KB |
Output is correct |
69 |
Correct |
376 ms |
15240 KB |
Output is correct |
70 |
Correct |
376 ms |
15368 KB |
Output is correct |
71 |
Correct |
371 ms |
15240 KB |
Output is correct |
72 |
Correct |
372 ms |
15240 KB |
Output is correct |
73 |
Correct |
386 ms |
27784 KB |
Output is correct |
74 |
Correct |
399 ms |
27912 KB |
Output is correct |
75 |
Correct |
372 ms |
15112 KB |
Output is correct |
76 |
Correct |
366 ms |
15240 KB |
Output is correct |
77 |
Correct |
385 ms |
15112 KB |
Output is correct |
78 |
Correct |
382 ms |
15112 KB |
Output is correct |
79 |
Correct |
378 ms |
15240 KB |
Output is correct |
80 |
Correct |
376 ms |
15112 KB |
Output is correct |
81 |
Correct |
345 ms |
15856 KB |
Output is correct |
82 |
Correct |
360 ms |
15480 KB |
Output is correct |
83 |
Correct |
382 ms |
20360 KB |
Output is correct |
84 |
Correct |
380 ms |
22536 KB |
Output is correct |
85 |
Correct |
382 ms |
22408 KB |
Output is correct |
86 |
Correct |
372 ms |
16648 KB |
Output is correct |
87 |
Correct |
374 ms |
16136 KB |
Output is correct |
88 |
Correct |
363 ms |
16520 KB |
Output is correct |
89 |
Correct |
369 ms |
16452 KB |
Output is correct |
90 |
Correct |
359 ms |
16264 KB |
Output is correct |
91 |
Correct |
366 ms |
16520 KB |
Output is correct |
92 |
Correct |
359 ms |
16904 KB |
Output is correct |
93 |
Correct |
351 ms |
19332 KB |
Output is correct |
94 |
Correct |
366 ms |
20976 KB |
Output is correct |
95 |
Correct |
360 ms |
19688 KB |
Output is correct |
96 |
Correct |
375 ms |
17800 KB |
Output is correct |
97 |
Correct |
360 ms |
16260 KB |
Output is correct |
98 |
Correct |
372 ms |
15880 KB |
Output is correct |
99 |
Correct |
382 ms |
15508 KB |
Output is correct |
100 |
Correct |
358 ms |
18784 KB |
Output is correct |
101 |
Correct |
374 ms |
16688 KB |
Output is correct |
102 |
Correct |
377 ms |
16008 KB |
Output is correct |
103 |
Correct |
393 ms |
15752 KB |
Output is correct |
104 |
Correct |
314 ms |
16240 KB |
Output is correct |
105 |
Correct |
401 ms |
24712 KB |
Output is correct |
106 |
Correct |
310 ms |
15852 KB |
Output is correct |
107 |
Correct |
311 ms |
15848 KB |
Output is correct |
108 |
Correct |
404 ms |
28552 KB |
Output is correct |
109 |
Correct |
315 ms |
16104 KB |
Output is correct |
110 |
Correct |
399 ms |
28936 KB |
Output is correct |
111 |
Correct |
363 ms |
15112 KB |
Output is correct |