#include<bits/stdc++.h>
using namespace std;
int n, x, y, ans = 0, dp[200001];
vector<int> vec[200001];
string s;
bool visited[200001];
void dfs(int x) {
int maxi = 0;
visited[x] = true;
for(int c : vec[x]) {
if(!visited[c]) {
dfs(c);
dp[x] += dp[c];
maxi = max(dp[c], maxi);
}
}
dp[x] = max(s[x - 1] - '0', dp[x] - s[x - 1] + '0');
ans = max(ans, max(maxi + s[x - 1] - '0', dp[x]));
}
int main() {
cin >> n;
for(int i = 1; i < n; i++) {
cin >> x >> y;
vec[x].push_back(y);
vec[y].push_back(x);
}
cin >> s;
dfs(n);
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
5208 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5044 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
5208 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5044 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
5208 KB |
Output is correct |
23 |
Correct |
2 ms |
5208 KB |
Output is correct |
24 |
Correct |
2 ms |
5212 KB |
Output is correct |
25 |
Correct |
3 ms |
5212 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
3 ms |
5212 KB |
Output is correct |
30 |
Correct |
2 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
5212 KB |
Output is correct |
32 |
Correct |
2 ms |
5212 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5044 KB |
Output is correct |
37 |
Correct |
2 ms |
5212 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
2 ms |
5212 KB |
Output is correct |
40 |
Correct |
2 ms |
5212 KB |
Output is correct |
41 |
Correct |
2 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
2 ms |
5212 KB |
Output is correct |
44 |
Correct |
2 ms |
5212 KB |
Output is correct |
45 |
Correct |
2 ms |
5212 KB |
Output is correct |
46 |
Correct |
2 ms |
5184 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
2 ms |
5212 KB |
Output is correct |
49 |
Correct |
3 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5220 KB |
Output is correct |
51 |
Correct |
3 ms |
5212 KB |
Output is correct |
52 |
Correct |
2 ms |
5212 KB |
Output is correct |
53 |
Correct |
2 ms |
5208 KB |
Output is correct |
54 |
Correct |
3 ms |
5212 KB |
Output is correct |
55 |
Correct |
3 ms |
5048 KB |
Output is correct |
56 |
Correct |
2 ms |
5212 KB |
Output is correct |
57 |
Correct |
2 ms |
5212 KB |
Output is correct |
58 |
Correct |
3 ms |
5212 KB |
Output is correct |
59 |
Correct |
2 ms |
5212 KB |
Output is correct |
60 |
Correct |
2 ms |
5212 KB |
Output is correct |
61 |
Correct |
2 ms |
5212 KB |
Output is correct |
62 |
Correct |
3 ms |
5300 KB |
Output is correct |
63 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
5208 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5044 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
5208 KB |
Output is correct |
23 |
Correct |
2 ms |
5208 KB |
Output is correct |
24 |
Correct |
2 ms |
5212 KB |
Output is correct |
25 |
Correct |
3 ms |
5212 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
3 ms |
5212 KB |
Output is correct |
30 |
Correct |
2 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
5212 KB |
Output is correct |
32 |
Correct |
2 ms |
5212 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5044 KB |
Output is correct |
37 |
Correct |
2 ms |
5212 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
2 ms |
5212 KB |
Output is correct |
40 |
Correct |
2 ms |
5212 KB |
Output is correct |
41 |
Correct |
2 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
2 ms |
5212 KB |
Output is correct |
44 |
Correct |
2 ms |
5212 KB |
Output is correct |
45 |
Correct |
2 ms |
5212 KB |
Output is correct |
46 |
Correct |
2 ms |
5184 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
2 ms |
5212 KB |
Output is correct |
49 |
Correct |
3 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5220 KB |
Output is correct |
51 |
Correct |
3 ms |
5212 KB |
Output is correct |
52 |
Correct |
2 ms |
5212 KB |
Output is correct |
53 |
Correct |
2 ms |
5208 KB |
Output is correct |
54 |
Correct |
3 ms |
5212 KB |
Output is correct |
55 |
Correct |
3 ms |
5048 KB |
Output is correct |
56 |
Correct |
2 ms |
5212 KB |
Output is correct |
57 |
Correct |
2 ms |
5212 KB |
Output is correct |
58 |
Correct |
3 ms |
5212 KB |
Output is correct |
59 |
Correct |
2 ms |
5212 KB |
Output is correct |
60 |
Correct |
2 ms |
5212 KB |
Output is correct |
61 |
Correct |
2 ms |
5212 KB |
Output is correct |
62 |
Correct |
3 ms |
5300 KB |
Output is correct |
63 |
Correct |
3 ms |
5212 KB |
Output is correct |
64 |
Correct |
126 ms |
12788 KB |
Output is correct |
65 |
Correct |
157 ms |
15332 KB |
Output is correct |
66 |
Correct |
167 ms |
15376 KB |
Output is correct |
67 |
Correct |
136 ms |
15336 KB |
Output is correct |
68 |
Correct |
169 ms |
15392 KB |
Output is correct |
69 |
Correct |
133 ms |
15336 KB |
Output is correct |
70 |
Correct |
139 ms |
15524 KB |
Output is correct |
71 |
Correct |
134 ms |
15376 KB |
Output is correct |
72 |
Correct |
155 ms |
15332 KB |
Output is correct |
73 |
Correct |
181 ms |
29176 KB |
Output is correct |
74 |
Correct |
165 ms |
26852 KB |
Output is correct |
75 |
Correct |
127 ms |
15372 KB |
Output is correct |
76 |
Correct |
143 ms |
15296 KB |
Output is correct |
77 |
Correct |
128 ms |
15336 KB |
Output is correct |
78 |
Correct |
132 ms |
15332 KB |
Output is correct |
79 |
Correct |
182 ms |
15344 KB |
Output is correct |
80 |
Correct |
158 ms |
15432 KB |
Output is correct |
81 |
Correct |
123 ms |
15820 KB |
Output is correct |
82 |
Correct |
122 ms |
15568 KB |
Output is correct |
83 |
Correct |
171 ms |
20380 KB |
Output is correct |
84 |
Correct |
135 ms |
21444 KB |
Output is correct |
85 |
Correct |
153 ms |
20952 KB |
Output is correct |
86 |
Correct |
139 ms |
16800 KB |
Output is correct |
87 |
Correct |
146 ms |
16724 KB |
Output is correct |
88 |
Correct |
138 ms |
16572 KB |
Output is correct |
89 |
Correct |
158 ms |
16736 KB |
Output is correct |
90 |
Correct |
151 ms |
16556 KB |
Output is correct |
91 |
Correct |
120 ms |
16684 KB |
Output is correct |
92 |
Correct |
128 ms |
16800 KB |
Output is correct |
93 |
Correct |
143 ms |
21600 KB |
Output is correct |
94 |
Correct |
150 ms |
19680 KB |
Output is correct |
95 |
Correct |
155 ms |
21576 KB |
Output is correct |
96 |
Correct |
130 ms |
19152 KB |
Output is correct |
97 |
Correct |
148 ms |
16332 KB |
Output is correct |
98 |
Correct |
141 ms |
15892 KB |
Output is correct |
99 |
Correct |
136 ms |
15760 KB |
Output is correct |
100 |
Correct |
156 ms |
18868 KB |
Output is correct |
101 |
Correct |
133 ms |
16956 KB |
Output is correct |
102 |
Correct |
125 ms |
16288 KB |
Output is correct |
103 |
Correct |
161 ms |
15908 KB |
Output is correct |
104 |
Correct |
120 ms |
16384 KB |
Output is correct |
105 |
Correct |
150 ms |
26480 KB |
Output is correct |
106 |
Correct |
121 ms |
16072 KB |
Output is correct |
107 |
Correct |
106 ms |
16052 KB |
Output is correct |
108 |
Correct |
144 ms |
27360 KB |
Output is correct |
109 |
Correct |
142 ms |
16280 KB |
Output is correct |
110 |
Correct |
156 ms |
30440 KB |
Output is correct |
111 |
Correct |
143 ms |
15332 KB |
Output is correct |