#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int> > adj;
int DP[200005];
bool type[200005];
int ans = 0;
void dfs(int c, int p) {
int sum = 0;
DP[c] = type[c] ? 1 : 0;
for(int n : adj[c]) {
if(n==p) continue;
dfs(n,c);
sum += DP[n];
ans = max(ans, DP[n] + DP[c]);
}
DP[c] = max(DP[c],sum-DP[c]);
ans = max(ans, DP[c]);
}
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
int i;
adj.resize(N);
for(i=0;i<N-1;i++) {
int a, b;
cin >>a >> b;
adj[a-1].push_back(b-1);
adj[b-1].push_back(a-1);
}
string s;
cin >> s;
for(i=0;i<N;i++) type[i] = s[i] == '1';
dfs(0, -1);
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
412 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
440 KB |
Output is correct |
44 |
Correct |
1 ms |
460 KB |
Output is correct |
45 |
Correct |
1 ms |
460 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
1 ms |
460 KB |
Output is correct |
52 |
Correct |
1 ms |
388 KB |
Output is correct |
53 |
Correct |
1 ms |
460 KB |
Output is correct |
54 |
Correct |
1 ms |
460 KB |
Output is correct |
55 |
Correct |
2 ms |
460 KB |
Output is correct |
56 |
Correct |
1 ms |
460 KB |
Output is correct |
57 |
Correct |
2 ms |
588 KB |
Output is correct |
58 |
Correct |
1 ms |
460 KB |
Output is correct |
59 |
Correct |
1 ms |
460 KB |
Output is correct |
60 |
Correct |
1 ms |
460 KB |
Output is correct |
61 |
Correct |
1 ms |
460 KB |
Output is correct |
62 |
Correct |
1 ms |
460 KB |
Output is correct |
63 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
412 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
440 KB |
Output is correct |
44 |
Correct |
1 ms |
460 KB |
Output is correct |
45 |
Correct |
1 ms |
460 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
1 ms |
460 KB |
Output is correct |
52 |
Correct |
1 ms |
388 KB |
Output is correct |
53 |
Correct |
1 ms |
460 KB |
Output is correct |
54 |
Correct |
1 ms |
460 KB |
Output is correct |
55 |
Correct |
2 ms |
460 KB |
Output is correct |
56 |
Correct |
1 ms |
460 KB |
Output is correct |
57 |
Correct |
2 ms |
588 KB |
Output is correct |
58 |
Correct |
1 ms |
460 KB |
Output is correct |
59 |
Correct |
1 ms |
460 KB |
Output is correct |
60 |
Correct |
1 ms |
460 KB |
Output is correct |
61 |
Correct |
1 ms |
460 KB |
Output is correct |
62 |
Correct |
1 ms |
460 KB |
Output is correct |
63 |
Correct |
1 ms |
460 KB |
Output is correct |
64 |
Correct |
111 ms |
14344 KB |
Output is correct |
65 |
Correct |
127 ms |
14420 KB |
Output is correct |
66 |
Correct |
120 ms |
14516 KB |
Output is correct |
67 |
Correct |
116 ms |
14336 KB |
Output is correct |
68 |
Correct |
120 ms |
14340 KB |
Output is correct |
69 |
Correct |
112 ms |
14388 KB |
Output is correct |
70 |
Correct |
116 ms |
14392 KB |
Output is correct |
71 |
Correct |
154 ms |
14376 KB |
Output is correct |
72 |
Correct |
127 ms |
14384 KB |
Output is correct |
73 |
Correct |
122 ms |
26060 KB |
Output is correct |
74 |
Correct |
137 ms |
25960 KB |
Output is correct |
75 |
Correct |
120 ms |
15596 KB |
Output is correct |
76 |
Correct |
143 ms |
15624 KB |
Output is correct |
77 |
Correct |
120 ms |
14392 KB |
Output is correct |
78 |
Correct |
118 ms |
14372 KB |
Output is correct |
79 |
Correct |
129 ms |
14344 KB |
Output is correct |
80 |
Correct |
116 ms |
14340 KB |
Output is correct |
81 |
Correct |
116 ms |
14500 KB |
Output is correct |
82 |
Correct |
112 ms |
14480 KB |
Output is correct |
83 |
Correct |
115 ms |
19416 KB |
Output is correct |
84 |
Correct |
135 ms |
21576 KB |
Output is correct |
85 |
Correct |
135 ms |
21296 KB |
Output is correct |
86 |
Correct |
110 ms |
15768 KB |
Output is correct |
87 |
Correct |
108 ms |
15160 KB |
Output is correct |
88 |
Correct |
102 ms |
15216 KB |
Output is correct |
89 |
Correct |
121 ms |
15432 KB |
Output is correct |
90 |
Correct |
115 ms |
15112 KB |
Output is correct |
91 |
Correct |
102 ms |
15292 KB |
Output is correct |
92 |
Correct |
107 ms |
15676 KB |
Output is correct |
93 |
Correct |
96 ms |
17968 KB |
Output is correct |
94 |
Correct |
125 ms |
19680 KB |
Output is correct |
95 |
Correct |
117 ms |
18268 KB |
Output is correct |
96 |
Correct |
116 ms |
16384 KB |
Output is correct |
97 |
Correct |
111 ms |
14948 KB |
Output is correct |
98 |
Correct |
124 ms |
14596 KB |
Output is correct |
99 |
Correct |
147 ms |
14620 KB |
Output is correct |
100 |
Correct |
139 ms |
17336 KB |
Output is correct |
101 |
Correct |
111 ms |
15360 KB |
Output is correct |
102 |
Correct |
101 ms |
14612 KB |
Output is correct |
103 |
Correct |
141 ms |
14644 KB |
Output is correct |
104 |
Correct |
68 ms |
14904 KB |
Output is correct |
105 |
Correct |
120 ms |
22876 KB |
Output is correct |
106 |
Correct |
66 ms |
15036 KB |
Output is correct |
107 |
Correct |
65 ms |
15028 KB |
Output is correct |
108 |
Correct |
144 ms |
26724 KB |
Output is correct |
109 |
Correct |
71 ms |
14928 KB |
Output is correct |
110 |
Correct |
122 ms |
27148 KB |
Output is correct |
111 |
Correct |
114 ms |
14312 KB |
Output is correct |