#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, u, v, dp1[nx], dp2[nx], ans;
vector<int> d[nx];
string s;
void dfs(int u, int p)
{
for (auto v:d[u])
{
if (v==p) continue;
dfs(v, u);
if (s[u-1]=='1') dp1[u]+=dp1[v], dp2[u]=max(dp2[u], dp1[v]+1);
else dp1[u]+=max(dp1[v], dp2[v]-2), dp2[u]=max(dp2[u], dp2[v]);
}
if (s[u-1]=='1') dp1[u]=max(1, dp1[u]-1), dp2[u]=max(dp2[u], 1);
ans=max({ans, dp1[u], dp2[u]});
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
cin>>s;
dfs(1, 1);
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 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 |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 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 |
4952 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 |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5164 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 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 |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 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 |
4952 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 |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5164 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
2 ms |
5272 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
2 ms |
5212 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
2 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 |
5212 KB |
Output is correct |
34 |
Correct |
2 ms |
5212 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5208 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 |
5176 KB |
Output is correct |
41 |
Correct |
2 ms |
5172 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 |
5208 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
2 ms |
5212 KB |
Output is correct |
49 |
Correct |
2 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
2 ms |
5252 KB |
Output is correct |
52 |
Correct |
2 ms |
5176 KB |
Output is correct |
53 |
Correct |
2 ms |
5212 KB |
Output is correct |
54 |
Correct |
2 ms |
5176 KB |
Output is correct |
55 |
Correct |
2 ms |
5212 KB |
Output is correct |
56 |
Correct |
1 ms |
5396 KB |
Output is correct |
57 |
Correct |
2 ms |
5212 KB |
Output is correct |
58 |
Correct |
2 ms |
5212 KB |
Output is correct |
59 |
Correct |
1 ms |
5212 KB |
Output is correct |
60 |
Correct |
2 ms |
5208 KB |
Output is correct |
61 |
Correct |
2 ms |
5208 KB |
Output is correct |
62 |
Correct |
2 ms |
5208 KB |
Output is correct |
63 |
Correct |
2 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 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 |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 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 |
4952 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 |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5164 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
2 ms |
5272 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
2 ms |
5212 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
2 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 |
5212 KB |
Output is correct |
34 |
Correct |
2 ms |
5212 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5208 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 |
5176 KB |
Output is correct |
41 |
Correct |
2 ms |
5172 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 |
5208 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
2 ms |
5212 KB |
Output is correct |
49 |
Correct |
2 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
2 ms |
5252 KB |
Output is correct |
52 |
Correct |
2 ms |
5176 KB |
Output is correct |
53 |
Correct |
2 ms |
5212 KB |
Output is correct |
54 |
Correct |
2 ms |
5176 KB |
Output is correct |
55 |
Correct |
2 ms |
5212 KB |
Output is correct |
56 |
Correct |
1 ms |
5396 KB |
Output is correct |
57 |
Correct |
2 ms |
5212 KB |
Output is correct |
58 |
Correct |
2 ms |
5212 KB |
Output is correct |
59 |
Correct |
1 ms |
5212 KB |
Output is correct |
60 |
Correct |
2 ms |
5208 KB |
Output is correct |
61 |
Correct |
2 ms |
5208 KB |
Output is correct |
62 |
Correct |
2 ms |
5208 KB |
Output is correct |
63 |
Correct |
2 ms |
5208 KB |
Output is correct |
64 |
Correct |
75 ms |
15892 KB |
Output is correct |
65 |
Correct |
86 ms |
16020 KB |
Output is correct |
66 |
Correct |
59 ms |
16000 KB |
Output is correct |
67 |
Correct |
78 ms |
15972 KB |
Output is correct |
68 |
Correct |
59 ms |
16000 KB |
Output is correct |
69 |
Correct |
62 ms |
16016 KB |
Output is correct |
70 |
Correct |
55 ms |
16036 KB |
Output is correct |
71 |
Correct |
55 ms |
16028 KB |
Output is correct |
72 |
Correct |
57 ms |
16008 KB |
Output is correct |
73 |
Correct |
73 ms |
28564 KB |
Output is correct |
74 |
Correct |
74 ms |
28564 KB |
Output is correct |
75 |
Correct |
56 ms |
15824 KB |
Output is correct |
76 |
Correct |
58 ms |
15768 KB |
Output is correct |
77 |
Correct |
67 ms |
16028 KB |
Output is correct |
78 |
Correct |
99 ms |
16012 KB |
Output is correct |
79 |
Correct |
58 ms |
15980 KB |
Output is correct |
80 |
Correct |
55 ms |
15952 KB |
Output is correct |
81 |
Correct |
51 ms |
16328 KB |
Output is correct |
82 |
Correct |
73 ms |
16464 KB |
Output is correct |
83 |
Correct |
66 ms |
21220 KB |
Output is correct |
84 |
Correct |
80 ms |
23204 KB |
Output is correct |
85 |
Correct |
72 ms |
22944 KB |
Output is correct |
86 |
Correct |
77 ms |
17300 KB |
Output is correct |
87 |
Correct |
59 ms |
16780 KB |
Output is correct |
88 |
Correct |
62 ms |
17104 KB |
Output is correct |
89 |
Correct |
59 ms |
17308 KB |
Output is correct |
90 |
Correct |
61 ms |
17052 KB |
Output is correct |
91 |
Correct |
69 ms |
17268 KB |
Output is correct |
92 |
Correct |
60 ms |
17536 KB |
Output is correct |
93 |
Correct |
62 ms |
20064 KB |
Output is correct |
94 |
Correct |
60 ms |
21820 KB |
Output is correct |
95 |
Correct |
58 ms |
20376 KB |
Output is correct |
96 |
Correct |
59 ms |
18684 KB |
Output is correct |
97 |
Correct |
71 ms |
17144 KB |
Output is correct |
98 |
Correct |
66 ms |
16616 KB |
Output is correct |
99 |
Correct |
55 ms |
16416 KB |
Output is correct |
100 |
Correct |
62 ms |
19584 KB |
Output is correct |
101 |
Correct |
60 ms |
17496 KB |
Output is correct |
102 |
Correct |
54 ms |
16740 KB |
Output is correct |
103 |
Correct |
68 ms |
16728 KB |
Output is correct |
104 |
Correct |
39 ms |
15420 KB |
Output is correct |
105 |
Correct |
71 ms |
25508 KB |
Output is correct |
106 |
Correct |
40 ms |
16836 KB |
Output is correct |
107 |
Correct |
41 ms |
16664 KB |
Output is correct |
108 |
Correct |
73 ms |
29368 KB |
Output is correct |
109 |
Correct |
39 ms |
15304 KB |
Output is correct |
110 |
Correct |
71 ms |
29584 KB |
Output is correct |
111 |
Correct |
54 ms |
15812 KB |
Output is correct |