#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=2e5;
int n, ans, dp[mxN];
string s;
vector<int> adj[mxN];
void dfs(int u=0, int p=-1) {
int mx=0;
dp[u]='0'-s[u];
for (int v : adj[u])
if (v!=p) {
dfs(v, u);
dp[u]+=max(dp[v], 0);
mx=max(mx, dp[v]);
}
ans=max(ans, mx+(s[u]=='1'));
if (s[u]=='1')
dp[u]=max(dp[u], 1);
ans=max(ans, dp[u]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=1; i<n; ++i) {
int u, v;
cin >> u >> v, --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cin >> s;
dfs();
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5024 KB |
Output is correct |
6 |
Correct |
3 ms |
5028 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5024 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 |
5028 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 |
5024 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5024 KB |
Output is correct |
6 |
Correct |
3 ms |
5028 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5024 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 |
5028 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 |
5024 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5036 KB |
Output is correct |
24 |
Correct |
4 ms |
5076 KB |
Output is correct |
25 |
Correct |
4 ms |
5060 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
3 ms |
5076 KB |
Output is correct |
34 |
Correct |
4 ms |
5036 KB |
Output is correct |
35 |
Correct |
5 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5016 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5168 KB |
Output is correct |
40 |
Correct |
3 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5160 KB |
Output is correct |
42 |
Correct |
4 ms |
5204 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5076 KB |
Output is correct |
47 |
Correct |
5 ms |
5036 KB |
Output is correct |
48 |
Correct |
3 ms |
5076 KB |
Output is correct |
49 |
Correct |
3 ms |
5076 KB |
Output is correct |
50 |
Correct |
5 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5076 KB |
Output is correct |
54 |
Correct |
4 ms |
5040 KB |
Output is correct |
55 |
Correct |
3 ms |
5084 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
4 ms |
5076 KB |
Output is correct |
59 |
Correct |
4 ms |
5036 KB |
Output is correct |
60 |
Correct |
3 ms |
5076 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5220 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5024 KB |
Output is correct |
6 |
Correct |
3 ms |
5028 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5024 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 |
5028 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 |
5024 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5036 KB |
Output is correct |
24 |
Correct |
4 ms |
5076 KB |
Output is correct |
25 |
Correct |
4 ms |
5060 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
3 ms |
5076 KB |
Output is correct |
34 |
Correct |
4 ms |
5036 KB |
Output is correct |
35 |
Correct |
5 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5016 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5168 KB |
Output is correct |
40 |
Correct |
3 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5160 KB |
Output is correct |
42 |
Correct |
4 ms |
5204 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5076 KB |
Output is correct |
47 |
Correct |
5 ms |
5036 KB |
Output is correct |
48 |
Correct |
3 ms |
5076 KB |
Output is correct |
49 |
Correct |
3 ms |
5076 KB |
Output is correct |
50 |
Correct |
5 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5076 KB |
Output is correct |
54 |
Correct |
4 ms |
5040 KB |
Output is correct |
55 |
Correct |
3 ms |
5084 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
4 ms |
5076 KB |
Output is correct |
59 |
Correct |
4 ms |
5036 KB |
Output is correct |
60 |
Correct |
3 ms |
5076 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5220 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
116 ms |
15156 KB |
Output is correct |
65 |
Correct |
131 ms |
15088 KB |
Output is correct |
66 |
Correct |
121 ms |
15096 KB |
Output is correct |
67 |
Correct |
112 ms |
15176 KB |
Output is correct |
68 |
Correct |
123 ms |
15132 KB |
Output is correct |
69 |
Correct |
138 ms |
15108 KB |
Output is correct |
70 |
Correct |
105 ms |
15132 KB |
Output is correct |
71 |
Correct |
114 ms |
15344 KB |
Output is correct |
72 |
Correct |
107 ms |
15112 KB |
Output is correct |
73 |
Correct |
146 ms |
27740 KB |
Output is correct |
74 |
Correct |
128 ms |
27816 KB |
Output is correct |
75 |
Correct |
138 ms |
15072 KB |
Output is correct |
76 |
Correct |
120 ms |
15060 KB |
Output is correct |
77 |
Correct |
123 ms |
15028 KB |
Output is correct |
78 |
Correct |
109 ms |
15028 KB |
Output is correct |
79 |
Correct |
140 ms |
15024 KB |
Output is correct |
80 |
Correct |
130 ms |
15028 KB |
Output is correct |
81 |
Correct |
101 ms |
15516 KB |
Output is correct |
82 |
Correct |
104 ms |
15184 KB |
Output is correct |
83 |
Correct |
139 ms |
20280 KB |
Output is correct |
84 |
Correct |
134 ms |
22428 KB |
Output is correct |
85 |
Correct |
124 ms |
22088 KB |
Output is correct |
86 |
Correct |
113 ms |
16464 KB |
Output is correct |
87 |
Correct |
110 ms |
15912 KB |
Output is correct |
88 |
Correct |
108 ms |
16320 KB |
Output is correct |
89 |
Correct |
119 ms |
16376 KB |
Output is correct |
90 |
Correct |
117 ms |
16236 KB |
Output is correct |
91 |
Correct |
108 ms |
16456 KB |
Output is correct |
92 |
Correct |
112 ms |
16728 KB |
Output is correct |
93 |
Correct |
140 ms |
19040 KB |
Output is correct |
94 |
Correct |
106 ms |
20888 KB |
Output is correct |
95 |
Correct |
98 ms |
19524 KB |
Output is correct |
96 |
Correct |
128 ms |
17724 KB |
Output is correct |
97 |
Correct |
113 ms |
16168 KB |
Output is correct |
98 |
Correct |
96 ms |
15688 KB |
Output is correct |
99 |
Correct |
114 ms |
15488 KB |
Output is correct |
100 |
Correct |
108 ms |
18680 KB |
Output is correct |
101 |
Correct |
114 ms |
16712 KB |
Output is correct |
102 |
Correct |
108 ms |
15864 KB |
Output is correct |
103 |
Correct |
103 ms |
15720 KB |
Output is correct |
104 |
Correct |
74 ms |
16056 KB |
Output is correct |
105 |
Correct |
148 ms |
24568 KB |
Output is correct |
106 |
Correct |
67 ms |
15936 KB |
Output is correct |
107 |
Correct |
87 ms |
16056 KB |
Output is correct |
108 |
Correct |
134 ms |
28504 KB |
Output is correct |
109 |
Correct |
70 ms |
15992 KB |
Output is correct |
110 |
Correct |
122 ms |
28896 KB |
Output is correct |
111 |
Correct |
103 ms |
15048 KB |
Output is correct |