#include <bits/stdc++.h>
using namespace std ;
const int MAX = 2e5 + 10 ;
int n ;
int mark[MAX] ;
vector< vector<int> >adj(MAX) ;
int ans = 0 ;
int dp[MAX] ;
void dfs(int node , int par)
{
int cnt = 0 ;
for(auto &child : adj[node])
{
if(child == par)
continue ;
dfs(child , node) ;
cnt += dp[child] ;
if(mark[node])
ans = max(ans , dp[child] + 1) ;
}
if(mark[node])
dp[node] = max(1 , cnt - 1) ;
else
dp[node] = cnt ;
ans = max(ans , dp[node]) ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n ;
for(int i = 0 ; i < n-1 ; ++i)
{
int x , y ;
cin>>x>>y ;
adj[x].push_back(y) ;
adj[y].push_back(x) ;
}
for(int i = 1 ; i <= n ; ++i)
{
char c ;
cin>>c ;
mark[i] = (c - '0') ;
}
dfs(1 , -1) ;
return cout<<ans<<"\n" , 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4904 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4904 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
4940 KB |
Output is correct |
22 |
Correct |
4 ms |
5068 KB |
Output is correct |
23 |
Correct |
5 ms |
5040 KB |
Output is correct |
24 |
Correct |
4 ms |
5052 KB |
Output is correct |
25 |
Correct |
5 ms |
5084 KB |
Output is correct |
26 |
Correct |
4 ms |
5068 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
4 ms |
5068 KB |
Output is correct |
29 |
Correct |
6 ms |
5196 KB |
Output is correct |
30 |
Correct |
5 ms |
5196 KB |
Output is correct |
31 |
Correct |
4 ms |
5092 KB |
Output is correct |
32 |
Correct |
4 ms |
5068 KB |
Output is correct |
33 |
Correct |
4 ms |
5104 KB |
Output is correct |
34 |
Correct |
4 ms |
5068 KB |
Output is correct |
35 |
Correct |
4 ms |
5068 KB |
Output is correct |
36 |
Correct |
4 ms |
5068 KB |
Output is correct |
37 |
Correct |
4 ms |
5068 KB |
Output is correct |
38 |
Correct |
4 ms |
5068 KB |
Output is correct |
39 |
Correct |
4 ms |
5172 KB |
Output is correct |
40 |
Correct |
4 ms |
5068 KB |
Output is correct |
41 |
Correct |
4 ms |
5068 KB |
Output is correct |
42 |
Correct |
4 ms |
5048 KB |
Output is correct |
43 |
Correct |
4 ms |
5068 KB |
Output is correct |
44 |
Correct |
4 ms |
5068 KB |
Output is correct |
45 |
Correct |
4 ms |
5044 KB |
Output is correct |
46 |
Correct |
4 ms |
5068 KB |
Output is correct |
47 |
Correct |
4 ms |
5068 KB |
Output is correct |
48 |
Correct |
4 ms |
5196 KB |
Output is correct |
49 |
Correct |
4 ms |
5196 KB |
Output is correct |
50 |
Correct |
4 ms |
5068 KB |
Output is correct |
51 |
Correct |
4 ms |
5044 KB |
Output is correct |
52 |
Correct |
4 ms |
5068 KB |
Output is correct |
53 |
Correct |
4 ms |
5048 KB |
Output is correct |
54 |
Correct |
4 ms |
5068 KB |
Output is correct |
55 |
Correct |
4 ms |
5088 KB |
Output is correct |
56 |
Correct |
4 ms |
5068 KB |
Output is correct |
57 |
Correct |
4 ms |
5196 KB |
Output is correct |
58 |
Correct |
4 ms |
5068 KB |
Output is correct |
59 |
Correct |
4 ms |
5068 KB |
Output is correct |
60 |
Correct |
4 ms |
5196 KB |
Output is correct |
61 |
Correct |
4 ms |
5044 KB |
Output is correct |
62 |
Correct |
4 ms |
5196 KB |
Output is correct |
63 |
Correct |
4 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4904 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
4940 KB |
Output is correct |
22 |
Correct |
4 ms |
5068 KB |
Output is correct |
23 |
Correct |
5 ms |
5040 KB |
Output is correct |
24 |
Correct |
4 ms |
5052 KB |
Output is correct |
25 |
Correct |
5 ms |
5084 KB |
Output is correct |
26 |
Correct |
4 ms |
5068 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
4 ms |
5068 KB |
Output is correct |
29 |
Correct |
6 ms |
5196 KB |
Output is correct |
30 |
Correct |
5 ms |
5196 KB |
Output is correct |
31 |
Correct |
4 ms |
5092 KB |
Output is correct |
32 |
Correct |
4 ms |
5068 KB |
Output is correct |
33 |
Correct |
4 ms |
5104 KB |
Output is correct |
34 |
Correct |
4 ms |
5068 KB |
Output is correct |
35 |
Correct |
4 ms |
5068 KB |
Output is correct |
36 |
Correct |
4 ms |
5068 KB |
Output is correct |
37 |
Correct |
4 ms |
5068 KB |
Output is correct |
38 |
Correct |
4 ms |
5068 KB |
Output is correct |
39 |
Correct |
4 ms |
5172 KB |
Output is correct |
40 |
Correct |
4 ms |
5068 KB |
Output is correct |
41 |
Correct |
4 ms |
5068 KB |
Output is correct |
42 |
Correct |
4 ms |
5048 KB |
Output is correct |
43 |
Correct |
4 ms |
5068 KB |
Output is correct |
44 |
Correct |
4 ms |
5068 KB |
Output is correct |
45 |
Correct |
4 ms |
5044 KB |
Output is correct |
46 |
Correct |
4 ms |
5068 KB |
Output is correct |
47 |
Correct |
4 ms |
5068 KB |
Output is correct |
48 |
Correct |
4 ms |
5196 KB |
Output is correct |
49 |
Correct |
4 ms |
5196 KB |
Output is correct |
50 |
Correct |
4 ms |
5068 KB |
Output is correct |
51 |
Correct |
4 ms |
5044 KB |
Output is correct |
52 |
Correct |
4 ms |
5068 KB |
Output is correct |
53 |
Correct |
4 ms |
5048 KB |
Output is correct |
54 |
Correct |
4 ms |
5068 KB |
Output is correct |
55 |
Correct |
4 ms |
5088 KB |
Output is correct |
56 |
Correct |
4 ms |
5068 KB |
Output is correct |
57 |
Correct |
4 ms |
5196 KB |
Output is correct |
58 |
Correct |
4 ms |
5068 KB |
Output is correct |
59 |
Correct |
4 ms |
5068 KB |
Output is correct |
60 |
Correct |
4 ms |
5196 KB |
Output is correct |
61 |
Correct |
4 ms |
5044 KB |
Output is correct |
62 |
Correct |
4 ms |
5196 KB |
Output is correct |
63 |
Correct |
4 ms |
5068 KB |
Output is correct |
64 |
Correct |
176 ms |
15628 KB |
Output is correct |
65 |
Correct |
158 ms |
15568 KB |
Output is correct |
66 |
Correct |
145 ms |
15596 KB |
Output is correct |
67 |
Correct |
151 ms |
15740 KB |
Output is correct |
68 |
Correct |
143 ms |
15556 KB |
Output is correct |
69 |
Correct |
153 ms |
15532 KB |
Output is correct |
70 |
Correct |
139 ms |
15556 KB |
Output is correct |
71 |
Correct |
143 ms |
15580 KB |
Output is correct |
72 |
Correct |
140 ms |
15660 KB |
Output is correct |
73 |
Correct |
168 ms |
28228 KB |
Output is correct |
74 |
Correct |
152 ms |
28100 KB |
Output is correct |
75 |
Correct |
165 ms |
15668 KB |
Output is correct |
76 |
Correct |
135 ms |
15428 KB |
Output is correct |
77 |
Correct |
141 ms |
15444 KB |
Output is correct |
78 |
Correct |
197 ms |
15496 KB |
Output is correct |
79 |
Correct |
199 ms |
15468 KB |
Output is correct |
80 |
Correct |
199 ms |
15520 KB |
Output is correct |
81 |
Correct |
159 ms |
15800 KB |
Output is correct |
82 |
Correct |
153 ms |
15660 KB |
Output is correct |
83 |
Correct |
154 ms |
20676 KB |
Output is correct |
84 |
Correct |
195 ms |
22884 KB |
Output is correct |
85 |
Correct |
176 ms |
22516 KB |
Output is correct |
86 |
Correct |
192 ms |
16876 KB |
Output is correct |
87 |
Correct |
187 ms |
16324 KB |
Output is correct |
88 |
Correct |
206 ms |
16808 KB |
Output is correct |
89 |
Correct |
154 ms |
16820 KB |
Output is correct |
90 |
Correct |
172 ms |
16596 KB |
Output is correct |
91 |
Correct |
207 ms |
16836 KB |
Output is correct |
92 |
Correct |
207 ms |
17200 KB |
Output is correct |
93 |
Correct |
199 ms |
19480 KB |
Output is correct |
94 |
Correct |
208 ms |
21180 KB |
Output is correct |
95 |
Correct |
188 ms |
20032 KB |
Output is correct |
96 |
Correct |
184 ms |
18236 KB |
Output is correct |
97 |
Correct |
147 ms |
16608 KB |
Output is correct |
98 |
Correct |
143 ms |
16192 KB |
Output is correct |
99 |
Correct |
172 ms |
16000 KB |
Output is correct |
100 |
Correct |
151 ms |
19140 KB |
Output is correct |
101 |
Correct |
189 ms |
17048 KB |
Output is correct |
102 |
Correct |
150 ms |
16472 KB |
Output is correct |
103 |
Correct |
154 ms |
16176 KB |
Output is correct |
104 |
Correct |
95 ms |
16408 KB |
Output is correct |
105 |
Correct |
201 ms |
25072 KB |
Output is correct |
106 |
Correct |
91 ms |
16184 KB |
Output is correct |
107 |
Correct |
98 ms |
16168 KB |
Output is correct |
108 |
Correct |
193 ms |
28944 KB |
Output is correct |
109 |
Correct |
116 ms |
16452 KB |
Output is correct |
110 |
Correct |
236 ms |
29252 KB |
Output is correct |
111 |
Correct |
147 ms |
15428 KB |
Output is correct |