#include <bits/stdc++.h>
//ako ovaj vaso daso misli da me pobedjuje.....
using namespace std;
#define int long long
#define f first
#define s second
const int N = 2e5 + 69;
int n, mark[N], dp[N], up[N];
vector<int> g[N];
string s;
void dfs(int v, int p) {
for (auto u : g[v]) {
if (u == p)
continue;
dfs(u, v);
dp[v] += dp[u];
}
dp[v] -= mark[v];
if (mark[v])
dp[v] = max(dp[v], 1ll);
}
int ans = 0;
void dfs1(int v, int p) {
ans = max(ans, dp[v]);
for (auto u : g[v]) {
if (u == p)
continue;
dfs1(u, v);
ans = max(ans, dp[u] + mark[v]);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1;i <= n - 1;i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
cin >> s;
for (int i = 0;i < n;i++) {
if (s[i] == '1')
mark[i + 1] = 1;
}
dfs(1, 0);
dfs1(1, 0);
cout << ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8844 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8840 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
9056 KB |
Output is correct |
14 |
Correct |
3 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
2 ms |
8948 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8844 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8840 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
9056 KB |
Output is correct |
14 |
Correct |
3 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
2 ms |
8948 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
2 ms |
8796 KB |
Output is correct |
23 |
Correct |
3 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
9048 KB |
Output is correct |
27 |
Correct |
3 ms |
8796 KB |
Output is correct |
28 |
Correct |
4 ms |
9308 KB |
Output is correct |
29 |
Correct |
3 ms |
9052 KB |
Output is correct |
30 |
Correct |
3 ms |
8796 KB |
Output is correct |
31 |
Correct |
3 ms |
8796 KB |
Output is correct |
32 |
Correct |
3 ms |
8796 KB |
Output is correct |
33 |
Correct |
4 ms |
8796 KB |
Output is correct |
34 |
Correct |
3 ms |
8796 KB |
Output is correct |
35 |
Correct |
3 ms |
8796 KB |
Output is correct |
36 |
Correct |
3 ms |
8800 KB |
Output is correct |
37 |
Correct |
3 ms |
8796 KB |
Output is correct |
38 |
Correct |
3 ms |
8796 KB |
Output is correct |
39 |
Correct |
2 ms |
8796 KB |
Output is correct |
40 |
Correct |
3 ms |
8796 KB |
Output is correct |
41 |
Correct |
3 ms |
8796 KB |
Output is correct |
42 |
Correct |
3 ms |
8796 KB |
Output is correct |
43 |
Correct |
2 ms |
8796 KB |
Output is correct |
44 |
Correct |
2 ms |
8796 KB |
Output is correct |
45 |
Correct |
3 ms |
8796 KB |
Output is correct |
46 |
Correct |
3 ms |
8796 KB |
Output is correct |
47 |
Correct |
2 ms |
8796 KB |
Output is correct |
48 |
Correct |
2 ms |
8796 KB |
Output is correct |
49 |
Correct |
2 ms |
8916 KB |
Output is correct |
50 |
Correct |
2 ms |
8904 KB |
Output is correct |
51 |
Correct |
3 ms |
8796 KB |
Output is correct |
52 |
Correct |
3 ms |
8796 KB |
Output is correct |
53 |
Correct |
4 ms |
9028 KB |
Output is correct |
54 |
Correct |
3 ms |
9048 KB |
Output is correct |
55 |
Correct |
3 ms |
8796 KB |
Output is correct |
56 |
Correct |
3 ms |
8888 KB |
Output is correct |
57 |
Correct |
2 ms |
9052 KB |
Output is correct |
58 |
Correct |
2 ms |
8796 KB |
Output is correct |
59 |
Correct |
3 ms |
8952 KB |
Output is correct |
60 |
Correct |
3 ms |
8796 KB |
Output is correct |
61 |
Correct |
3 ms |
8796 KB |
Output is correct |
62 |
Correct |
2 ms |
8796 KB |
Output is correct |
63 |
Correct |
3 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8844 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8840 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
9056 KB |
Output is correct |
14 |
Correct |
3 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
2 ms |
8948 KB |
Output is correct |
18 |
Correct |
3 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
2 ms |
8796 KB |
Output is correct |
23 |
Correct |
3 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8796 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
9048 KB |
Output is correct |
27 |
Correct |
3 ms |
8796 KB |
Output is correct |
28 |
Correct |
4 ms |
9308 KB |
Output is correct |
29 |
Correct |
3 ms |
9052 KB |
Output is correct |
30 |
Correct |
3 ms |
8796 KB |
Output is correct |
31 |
Correct |
3 ms |
8796 KB |
Output is correct |
32 |
Correct |
3 ms |
8796 KB |
Output is correct |
33 |
Correct |
4 ms |
8796 KB |
Output is correct |
34 |
Correct |
3 ms |
8796 KB |
Output is correct |
35 |
Correct |
3 ms |
8796 KB |
Output is correct |
36 |
Correct |
3 ms |
8800 KB |
Output is correct |
37 |
Correct |
3 ms |
8796 KB |
Output is correct |
38 |
Correct |
3 ms |
8796 KB |
Output is correct |
39 |
Correct |
2 ms |
8796 KB |
Output is correct |
40 |
Correct |
3 ms |
8796 KB |
Output is correct |
41 |
Correct |
3 ms |
8796 KB |
Output is correct |
42 |
Correct |
3 ms |
8796 KB |
Output is correct |
43 |
Correct |
2 ms |
8796 KB |
Output is correct |
44 |
Correct |
2 ms |
8796 KB |
Output is correct |
45 |
Correct |
3 ms |
8796 KB |
Output is correct |
46 |
Correct |
3 ms |
8796 KB |
Output is correct |
47 |
Correct |
2 ms |
8796 KB |
Output is correct |
48 |
Correct |
2 ms |
8796 KB |
Output is correct |
49 |
Correct |
2 ms |
8916 KB |
Output is correct |
50 |
Correct |
2 ms |
8904 KB |
Output is correct |
51 |
Correct |
3 ms |
8796 KB |
Output is correct |
52 |
Correct |
3 ms |
8796 KB |
Output is correct |
53 |
Correct |
4 ms |
9028 KB |
Output is correct |
54 |
Correct |
3 ms |
9048 KB |
Output is correct |
55 |
Correct |
3 ms |
8796 KB |
Output is correct |
56 |
Correct |
3 ms |
8888 KB |
Output is correct |
57 |
Correct |
2 ms |
9052 KB |
Output is correct |
58 |
Correct |
2 ms |
8796 KB |
Output is correct |
59 |
Correct |
3 ms |
8952 KB |
Output is correct |
60 |
Correct |
3 ms |
8796 KB |
Output is correct |
61 |
Correct |
3 ms |
8796 KB |
Output is correct |
62 |
Correct |
2 ms |
8796 KB |
Output is correct |
63 |
Correct |
3 ms |
8796 KB |
Output is correct |
64 |
Correct |
84 ms |
20224 KB |
Output is correct |
65 |
Correct |
88 ms |
20092 KB |
Output is correct |
66 |
Correct |
89 ms |
20244 KB |
Output is correct |
67 |
Correct |
132 ms |
20112 KB |
Output is correct |
68 |
Correct |
85 ms |
20100 KB |
Output is correct |
69 |
Correct |
117 ms |
20368 KB |
Output is correct |
70 |
Correct |
137 ms |
20180 KB |
Output is correct |
71 |
Correct |
79 ms |
20104 KB |
Output is correct |
72 |
Correct |
101 ms |
18556 KB |
Output is correct |
73 |
Correct |
163 ms |
31636 KB |
Output is correct |
74 |
Correct |
132 ms |
31776 KB |
Output is correct |
75 |
Correct |
84 ms |
21392 KB |
Output is correct |
76 |
Correct |
113 ms |
21392 KB |
Output is correct |
77 |
Correct |
96 ms |
20168 KB |
Output is correct |
78 |
Correct |
129 ms |
20108 KB |
Output is correct |
79 |
Correct |
86 ms |
20160 KB |
Output is correct |
80 |
Correct |
101 ms |
20024 KB |
Output is correct |
81 |
Correct |
97 ms |
20168 KB |
Output is correct |
82 |
Correct |
79 ms |
20216 KB |
Output is correct |
83 |
Correct |
108 ms |
25124 KB |
Output is correct |
84 |
Correct |
128 ms |
27460 KB |
Output is correct |
85 |
Correct |
111 ms |
27040 KB |
Output is correct |
86 |
Correct |
114 ms |
21572 KB |
Output is correct |
87 |
Correct |
88 ms |
20928 KB |
Output is correct |
88 |
Correct |
114 ms |
21112 KB |
Output is correct |
89 |
Correct |
85 ms |
20896 KB |
Output is correct |
90 |
Correct |
88 ms |
20728 KB |
Output is correct |
91 |
Correct |
129 ms |
21112 KB |
Output is correct |
92 |
Correct |
159 ms |
21296 KB |
Output is correct |
93 |
Correct |
114 ms |
23696 KB |
Output is correct |
94 |
Correct |
84 ms |
25312 KB |
Output is correct |
95 |
Correct |
90 ms |
24000 KB |
Output is correct |
96 |
Correct |
81 ms |
22288 KB |
Output is correct |
97 |
Correct |
83 ms |
20716 KB |
Output is correct |
98 |
Correct |
78 ms |
20416 KB |
Output is correct |
99 |
Correct |
72 ms |
20112 KB |
Output is correct |
100 |
Correct |
109 ms |
23056 KB |
Output is correct |
101 |
Correct |
123 ms |
21208 KB |
Output is correct |
102 |
Correct |
75 ms |
20324 KB |
Output is correct |
103 |
Correct |
81 ms |
20464 KB |
Output is correct |
104 |
Correct |
42 ms |
17820 KB |
Output is correct |
105 |
Correct |
213 ms |
27572 KB |
Output is correct |
106 |
Correct |
45 ms |
20676 KB |
Output is correct |
107 |
Correct |
46 ms |
20672 KB |
Output is correct |
108 |
Correct |
135 ms |
31564 KB |
Output is correct |
109 |
Correct |
60 ms |
19904 KB |
Output is correct |
110 |
Correct |
137 ms |
31776 KB |
Output is correct |
111 |
Correct |
117 ms |
20104 KB |
Output is correct |