#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, x, y, answer = 0;
string power;
vector<ll> adj[200005];
ll dp[200005], ans[200005];
vector<ll> visited;
void dfs(ll from)
{
visited[from] = true;
ll summ = 0, maxx = 0;
for (ll u: adj[from])
{
if (visited[u]) continue;
dfs(u);
summ+=dp[u];
maxx = max(maxx, dp[u]);
}
if (power[from-1]=='1') {
ans[from] = max(summ-1, maxx + 1);
dp[from] = max(1LL, summ-1);
}
else {
ans[from] = dp[from] = summ;
}
answer = max(answer, ans[from]);
}
int main()
{
cin>>n;
for (ll i=0; i<n-1; ++i)
{
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
cin >> power;
visited.assign(n+1, false);
dfs(1);
cout<<answer<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8028 KB |
Output is correct |
2 |
Correct |
2 ms |
8088 KB |
Output is correct |
3 |
Correct |
2 ms |
8092 KB |
Output is correct |
4 |
Correct |
2 ms |
8092 KB |
Output is correct |
5 |
Correct |
2 ms |
8028 KB |
Output is correct |
6 |
Correct |
3 ms |
8076 KB |
Output is correct |
7 |
Correct |
3 ms |
8024 KB |
Output is correct |
8 |
Correct |
2 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
2 ms |
8028 KB |
Output is correct |
11 |
Correct |
2 ms |
8028 KB |
Output is correct |
12 |
Correct |
2 ms |
8028 KB |
Output is correct |
13 |
Correct |
2 ms |
8028 KB |
Output is correct |
14 |
Correct |
3 ms |
8028 KB |
Output is correct |
15 |
Correct |
3 ms |
8028 KB |
Output is correct |
16 |
Correct |
2 ms |
8040 KB |
Output is correct |
17 |
Correct |
2 ms |
8028 KB |
Output is correct |
18 |
Correct |
3 ms |
8048 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8028 KB |
Output is correct |
21 |
Correct |
2 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8028 KB |
Output is correct |
2 |
Correct |
2 ms |
8088 KB |
Output is correct |
3 |
Correct |
2 ms |
8092 KB |
Output is correct |
4 |
Correct |
2 ms |
8092 KB |
Output is correct |
5 |
Correct |
2 ms |
8028 KB |
Output is correct |
6 |
Correct |
3 ms |
8076 KB |
Output is correct |
7 |
Correct |
3 ms |
8024 KB |
Output is correct |
8 |
Correct |
2 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
2 ms |
8028 KB |
Output is correct |
11 |
Correct |
2 ms |
8028 KB |
Output is correct |
12 |
Correct |
2 ms |
8028 KB |
Output is correct |
13 |
Correct |
2 ms |
8028 KB |
Output is correct |
14 |
Correct |
3 ms |
8028 KB |
Output is correct |
15 |
Correct |
3 ms |
8028 KB |
Output is correct |
16 |
Correct |
2 ms |
8040 KB |
Output is correct |
17 |
Correct |
2 ms |
8028 KB |
Output is correct |
18 |
Correct |
3 ms |
8048 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8028 KB |
Output is correct |
21 |
Correct |
2 ms |
8280 KB |
Output is correct |
22 |
Correct |
4 ms |
8028 KB |
Output is correct |
23 |
Correct |
3 ms |
8028 KB |
Output is correct |
24 |
Correct |
3 ms |
8028 KB |
Output is correct |
25 |
Correct |
3 ms |
8028 KB |
Output is correct |
26 |
Correct |
3 ms |
8028 KB |
Output is correct |
27 |
Correct |
3 ms |
8028 KB |
Output is correct |
28 |
Correct |
3 ms |
8112 KB |
Output is correct |
29 |
Correct |
3 ms |
8284 KB |
Output is correct |
30 |
Correct |
4 ms |
8436 KB |
Output is correct |
31 |
Correct |
3 ms |
8096 KB |
Output is correct |
32 |
Correct |
3 ms |
8028 KB |
Output is correct |
33 |
Correct |
3 ms |
8028 KB |
Output is correct |
34 |
Correct |
3 ms |
8028 KB |
Output is correct |
35 |
Correct |
3 ms |
8028 KB |
Output is correct |
36 |
Correct |
3 ms |
8028 KB |
Output is correct |
37 |
Correct |
3 ms |
8024 KB |
Output is correct |
38 |
Correct |
3 ms |
8028 KB |
Output is correct |
39 |
Correct |
3 ms |
8104 KB |
Output is correct |
40 |
Correct |
3 ms |
8028 KB |
Output is correct |
41 |
Correct |
3 ms |
8284 KB |
Output is correct |
42 |
Correct |
3 ms |
8028 KB |
Output is correct |
43 |
Correct |
3 ms |
8024 KB |
Output is correct |
44 |
Correct |
3 ms |
8028 KB |
Output is correct |
45 |
Correct |
3 ms |
8028 KB |
Output is correct |
46 |
Correct |
3 ms |
8092 KB |
Output is correct |
47 |
Correct |
3 ms |
8024 KB |
Output is correct |
48 |
Correct |
3 ms |
8284 KB |
Output is correct |
49 |
Correct |
4 ms |
8284 KB |
Output is correct |
50 |
Correct |
3 ms |
8120 KB |
Output is correct |
51 |
Correct |
3 ms |
8024 KB |
Output is correct |
52 |
Correct |
3 ms |
8028 KB |
Output is correct |
53 |
Correct |
3 ms |
8028 KB |
Output is correct |
54 |
Correct |
3 ms |
8028 KB |
Output is correct |
55 |
Correct |
4 ms |
8028 KB |
Output is correct |
56 |
Correct |
3 ms |
8028 KB |
Output is correct |
57 |
Correct |
4 ms |
8280 KB |
Output is correct |
58 |
Correct |
3 ms |
8024 KB |
Output is correct |
59 |
Correct |
3 ms |
8028 KB |
Output is correct |
60 |
Correct |
3 ms |
8284 KB |
Output is correct |
61 |
Correct |
4 ms |
8024 KB |
Output is correct |
62 |
Correct |
3 ms |
8300 KB |
Output is correct |
63 |
Correct |
3 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8028 KB |
Output is correct |
2 |
Correct |
2 ms |
8088 KB |
Output is correct |
3 |
Correct |
2 ms |
8092 KB |
Output is correct |
4 |
Correct |
2 ms |
8092 KB |
Output is correct |
5 |
Correct |
2 ms |
8028 KB |
Output is correct |
6 |
Correct |
3 ms |
8076 KB |
Output is correct |
7 |
Correct |
3 ms |
8024 KB |
Output is correct |
8 |
Correct |
2 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
2 ms |
8028 KB |
Output is correct |
11 |
Correct |
2 ms |
8028 KB |
Output is correct |
12 |
Correct |
2 ms |
8028 KB |
Output is correct |
13 |
Correct |
2 ms |
8028 KB |
Output is correct |
14 |
Correct |
3 ms |
8028 KB |
Output is correct |
15 |
Correct |
3 ms |
8028 KB |
Output is correct |
16 |
Correct |
2 ms |
8040 KB |
Output is correct |
17 |
Correct |
2 ms |
8028 KB |
Output is correct |
18 |
Correct |
3 ms |
8048 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8028 KB |
Output is correct |
21 |
Correct |
2 ms |
8280 KB |
Output is correct |
22 |
Correct |
4 ms |
8028 KB |
Output is correct |
23 |
Correct |
3 ms |
8028 KB |
Output is correct |
24 |
Correct |
3 ms |
8028 KB |
Output is correct |
25 |
Correct |
3 ms |
8028 KB |
Output is correct |
26 |
Correct |
3 ms |
8028 KB |
Output is correct |
27 |
Correct |
3 ms |
8028 KB |
Output is correct |
28 |
Correct |
3 ms |
8112 KB |
Output is correct |
29 |
Correct |
3 ms |
8284 KB |
Output is correct |
30 |
Correct |
4 ms |
8436 KB |
Output is correct |
31 |
Correct |
3 ms |
8096 KB |
Output is correct |
32 |
Correct |
3 ms |
8028 KB |
Output is correct |
33 |
Correct |
3 ms |
8028 KB |
Output is correct |
34 |
Correct |
3 ms |
8028 KB |
Output is correct |
35 |
Correct |
3 ms |
8028 KB |
Output is correct |
36 |
Correct |
3 ms |
8028 KB |
Output is correct |
37 |
Correct |
3 ms |
8024 KB |
Output is correct |
38 |
Correct |
3 ms |
8028 KB |
Output is correct |
39 |
Correct |
3 ms |
8104 KB |
Output is correct |
40 |
Correct |
3 ms |
8028 KB |
Output is correct |
41 |
Correct |
3 ms |
8284 KB |
Output is correct |
42 |
Correct |
3 ms |
8028 KB |
Output is correct |
43 |
Correct |
3 ms |
8024 KB |
Output is correct |
44 |
Correct |
3 ms |
8028 KB |
Output is correct |
45 |
Correct |
3 ms |
8028 KB |
Output is correct |
46 |
Correct |
3 ms |
8092 KB |
Output is correct |
47 |
Correct |
3 ms |
8024 KB |
Output is correct |
48 |
Correct |
3 ms |
8284 KB |
Output is correct |
49 |
Correct |
4 ms |
8284 KB |
Output is correct |
50 |
Correct |
3 ms |
8120 KB |
Output is correct |
51 |
Correct |
3 ms |
8024 KB |
Output is correct |
52 |
Correct |
3 ms |
8028 KB |
Output is correct |
53 |
Correct |
3 ms |
8028 KB |
Output is correct |
54 |
Correct |
3 ms |
8028 KB |
Output is correct |
55 |
Correct |
4 ms |
8028 KB |
Output is correct |
56 |
Correct |
3 ms |
8028 KB |
Output is correct |
57 |
Correct |
4 ms |
8280 KB |
Output is correct |
58 |
Correct |
3 ms |
8024 KB |
Output is correct |
59 |
Correct |
3 ms |
8028 KB |
Output is correct |
60 |
Correct |
3 ms |
8284 KB |
Output is correct |
61 |
Correct |
4 ms |
8024 KB |
Output is correct |
62 |
Correct |
3 ms |
8300 KB |
Output is correct |
63 |
Correct |
3 ms |
8028 KB |
Output is correct |
64 |
Correct |
143 ms |
20200 KB |
Output is correct |
65 |
Correct |
196 ms |
20356 KB |
Output is correct |
66 |
Correct |
138 ms |
20196 KB |
Output is correct |
67 |
Correct |
149 ms |
20008 KB |
Output is correct |
68 |
Correct |
153 ms |
20200 KB |
Output is correct |
69 |
Correct |
140 ms |
20140 KB |
Output is correct |
70 |
Correct |
143 ms |
20076 KB |
Output is correct |
71 |
Correct |
149 ms |
20204 KB |
Output is correct |
72 |
Correct |
169 ms |
20552 KB |
Output is correct |
73 |
Correct |
161 ms |
31808 KB |
Output is correct |
74 |
Correct |
157 ms |
31772 KB |
Output is correct |
75 |
Correct |
162 ms |
21460 KB |
Output is correct |
76 |
Correct |
147 ms |
21448 KB |
Output is correct |
77 |
Correct |
147 ms |
19992 KB |
Output is correct |
78 |
Correct |
139 ms |
20152 KB |
Output is correct |
79 |
Correct |
145 ms |
20048 KB |
Output is correct |
80 |
Correct |
135 ms |
20112 KB |
Output is correct |
81 |
Correct |
146 ms |
20168 KB |
Output is correct |
82 |
Correct |
136 ms |
20244 KB |
Output is correct |
83 |
Correct |
158 ms |
25316 KB |
Output is correct |
84 |
Correct |
155 ms |
27368 KB |
Output is correct |
85 |
Correct |
161 ms |
27116 KB |
Output is correct |
86 |
Correct |
146 ms |
21476 KB |
Output is correct |
87 |
Correct |
146 ms |
20964 KB |
Output is correct |
88 |
Correct |
156 ms |
21220 KB |
Output is correct |
89 |
Correct |
147 ms |
20960 KB |
Output is correct |
90 |
Correct |
147 ms |
20676 KB |
Output is correct |
91 |
Correct |
138 ms |
20964 KB |
Output is correct |
92 |
Correct |
142 ms |
21396 KB |
Output is correct |
93 |
Correct |
134 ms |
23564 KB |
Output is correct |
94 |
Correct |
152 ms |
25120 KB |
Output is correct |
95 |
Correct |
160 ms |
23996 KB |
Output is correct |
96 |
Correct |
142 ms |
22208 KB |
Output is correct |
97 |
Correct |
137 ms |
20712 KB |
Output is correct |
98 |
Correct |
132 ms |
20344 KB |
Output is correct |
99 |
Correct |
156 ms |
20200 KB |
Output is correct |
100 |
Correct |
142 ms |
23188 KB |
Output is correct |
101 |
Correct |
159 ms |
21072 KB |
Output is correct |
102 |
Correct |
145 ms |
20380 KB |
Output is correct |
103 |
Correct |
136 ms |
20448 KB |
Output is correct |
104 |
Correct |
139 ms |
20868 KB |
Output is correct |
105 |
Correct |
171 ms |
28700 KB |
Output is correct |
106 |
Correct |
113 ms |
20676 KB |
Output is correct |
107 |
Correct |
122 ms |
20668 KB |
Output is correct |
108 |
Correct |
188 ms |
32480 KB |
Output is correct |
109 |
Correct |
120 ms |
20664 KB |
Output is correct |
110 |
Correct |
177 ms |
32696 KB |
Output is correct |
111 |
Correct |
134 ms |
19940 KB |
Output is correct |