//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
//#define _int __int128
#define int long long
int n;
vector<int>e[200005];
int dp[200005];
int ar[200005];
void init(){
cin>>n;
for(int i=1;i<=n-1;i++){
int a;int b;
cin>>a>>b;
e[a].push_back(b);
e[b].push_back(a);
}
string s;
cin>>s;
for(int i=0;i<n;i++){
ar[i+1]=s[i]-'0';
}
}
int ans;
void dfs(int nw,int pa){
for(auto v:e[nw]){
if(v==pa){continue;}
dfs(v,nw);
}
if(ar[nw]==0){
for(auto v:e[nw]){
if(v==pa){continue;}
dp[nw]+=dp[v];
}
}else{
dp[nw]=-1;
for(auto v:e[nw]){
if(v==pa){continue;}
dp[nw]+=dp[v];
ans=max(ans,dp[v]+1);
}
dp[nw]=max(1ll,dp[nw]);
}
ans=max(ans,dp[nw]);
}
signed main(){
init();
dfs(1,0);
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
1 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
8028 KB |
Output is correct |
5 |
Correct |
2 ms |
8092 KB |
Output is correct |
6 |
Correct |
2 ms |
8028 KB |
Output is correct |
7 |
Correct |
2 ms |
8288 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 |
5980 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 |
2 ms |
8028 KB |
Output is correct |
15 |
Correct |
2 ms |
5812 KB |
Output is correct |
16 |
Correct |
2 ms |
8028 KB |
Output is correct |
17 |
Correct |
2 ms |
8028 KB |
Output is correct |
18 |
Correct |
2 ms |
8028 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8084 KB |
Output is correct |
21 |
Correct |
2 ms |
8028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
1 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
8028 KB |
Output is correct |
5 |
Correct |
2 ms |
8092 KB |
Output is correct |
6 |
Correct |
2 ms |
8028 KB |
Output is correct |
7 |
Correct |
2 ms |
8288 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 |
5980 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 |
2 ms |
8028 KB |
Output is correct |
15 |
Correct |
2 ms |
5812 KB |
Output is correct |
16 |
Correct |
2 ms |
8028 KB |
Output is correct |
17 |
Correct |
2 ms |
8028 KB |
Output is correct |
18 |
Correct |
2 ms |
8028 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8084 KB |
Output is correct |
21 |
Correct |
2 ms |
8028 KB |
Output is correct |
22 |
Correct |
3 ms |
8024 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 |
8024 KB |
Output is correct |
26 |
Correct |
3 ms |
8028 KB |
Output is correct |
27 |
Correct |
3 ms |
6236 KB |
Output is correct |
28 |
Correct |
3 ms |
5980 KB |
Output is correct |
29 |
Correct |
3 ms |
8028 KB |
Output is correct |
30 |
Correct |
3 ms |
8028 KB |
Output is correct |
31 |
Correct |
3 ms |
8024 KB |
Output is correct |
32 |
Correct |
3 ms |
8028 KB |
Output is correct |
33 |
Correct |
4 ms |
8028 KB |
Output is correct |
34 |
Correct |
3 ms |
8028 KB |
Output is correct |
35 |
Correct |
3 ms |
5980 KB |
Output is correct |
36 |
Correct |
2 ms |
5980 KB |
Output is correct |
37 |
Correct |
3 ms |
8028 KB |
Output is correct |
38 |
Correct |
3 ms |
5980 KB |
Output is correct |
39 |
Correct |
3 ms |
8028 KB |
Output is correct |
40 |
Correct |
3 ms |
8028 KB |
Output is correct |
41 |
Correct |
3 ms |
5976 KB |
Output is correct |
42 |
Correct |
3 ms |
5980 KB |
Output is correct |
43 |
Correct |
3 ms |
8028 KB |
Output is correct |
44 |
Correct |
3 ms |
8028 KB |
Output is correct |
45 |
Correct |
3 ms |
8100 KB |
Output is correct |
46 |
Correct |
3 ms |
8028 KB |
Output is correct |
47 |
Correct |
3 ms |
5980 KB |
Output is correct |
48 |
Correct |
3 ms |
5976 KB |
Output is correct |
49 |
Correct |
3 ms |
8024 KB |
Output is correct |
50 |
Correct |
3 ms |
8028 KB |
Output is correct |
51 |
Correct |
4 ms |
8024 KB |
Output is correct |
52 |
Correct |
3 ms |
8028 KB |
Output is correct |
53 |
Correct |
2 ms |
5980 KB |
Output is correct |
54 |
Correct |
3 ms |
8028 KB |
Output is correct |
55 |
Correct |
3 ms |
8028 KB |
Output is correct |
56 |
Correct |
3 ms |
5980 KB |
Output is correct |
57 |
Correct |
3 ms |
6116 KB |
Output is correct |
58 |
Correct |
3 ms |
8028 KB |
Output is correct |
59 |
Correct |
3 ms |
8028 KB |
Output is correct |
60 |
Correct |
3 ms |
8028 KB |
Output is correct |
61 |
Correct |
2 ms |
5976 KB |
Output is correct |
62 |
Correct |
3 ms |
8028 KB |
Output is correct |
63 |
Correct |
3 ms |
8152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
1 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
8028 KB |
Output is correct |
5 |
Correct |
2 ms |
8092 KB |
Output is correct |
6 |
Correct |
2 ms |
8028 KB |
Output is correct |
7 |
Correct |
2 ms |
8288 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 |
5980 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 |
2 ms |
8028 KB |
Output is correct |
15 |
Correct |
2 ms |
5812 KB |
Output is correct |
16 |
Correct |
2 ms |
8028 KB |
Output is correct |
17 |
Correct |
2 ms |
8028 KB |
Output is correct |
18 |
Correct |
2 ms |
8028 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8084 KB |
Output is correct |
21 |
Correct |
2 ms |
8028 KB |
Output is correct |
22 |
Correct |
3 ms |
8024 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 |
8024 KB |
Output is correct |
26 |
Correct |
3 ms |
8028 KB |
Output is correct |
27 |
Correct |
3 ms |
6236 KB |
Output is correct |
28 |
Correct |
3 ms |
5980 KB |
Output is correct |
29 |
Correct |
3 ms |
8028 KB |
Output is correct |
30 |
Correct |
3 ms |
8028 KB |
Output is correct |
31 |
Correct |
3 ms |
8024 KB |
Output is correct |
32 |
Correct |
3 ms |
8028 KB |
Output is correct |
33 |
Correct |
4 ms |
8028 KB |
Output is correct |
34 |
Correct |
3 ms |
8028 KB |
Output is correct |
35 |
Correct |
3 ms |
5980 KB |
Output is correct |
36 |
Correct |
2 ms |
5980 KB |
Output is correct |
37 |
Correct |
3 ms |
8028 KB |
Output is correct |
38 |
Correct |
3 ms |
5980 KB |
Output is correct |
39 |
Correct |
3 ms |
8028 KB |
Output is correct |
40 |
Correct |
3 ms |
8028 KB |
Output is correct |
41 |
Correct |
3 ms |
5976 KB |
Output is correct |
42 |
Correct |
3 ms |
5980 KB |
Output is correct |
43 |
Correct |
3 ms |
8028 KB |
Output is correct |
44 |
Correct |
3 ms |
8028 KB |
Output is correct |
45 |
Correct |
3 ms |
8100 KB |
Output is correct |
46 |
Correct |
3 ms |
8028 KB |
Output is correct |
47 |
Correct |
3 ms |
5980 KB |
Output is correct |
48 |
Correct |
3 ms |
5976 KB |
Output is correct |
49 |
Correct |
3 ms |
8024 KB |
Output is correct |
50 |
Correct |
3 ms |
8028 KB |
Output is correct |
51 |
Correct |
4 ms |
8024 KB |
Output is correct |
52 |
Correct |
3 ms |
8028 KB |
Output is correct |
53 |
Correct |
2 ms |
5980 KB |
Output is correct |
54 |
Correct |
3 ms |
8028 KB |
Output is correct |
55 |
Correct |
3 ms |
8028 KB |
Output is correct |
56 |
Correct |
3 ms |
5980 KB |
Output is correct |
57 |
Correct |
3 ms |
6116 KB |
Output is correct |
58 |
Correct |
3 ms |
8028 KB |
Output is correct |
59 |
Correct |
3 ms |
8028 KB |
Output is correct |
60 |
Correct |
3 ms |
8028 KB |
Output is correct |
61 |
Correct |
2 ms |
5976 KB |
Output is correct |
62 |
Correct |
3 ms |
8028 KB |
Output is correct |
63 |
Correct |
3 ms |
8152 KB |
Output is correct |
64 |
Correct |
123 ms |
18404 KB |
Output is correct |
65 |
Correct |
140 ms |
18424 KB |
Output is correct |
66 |
Correct |
125 ms |
18400 KB |
Output is correct |
67 |
Correct |
146 ms |
18464 KB |
Output is correct |
68 |
Correct |
124 ms |
18400 KB |
Output is correct |
69 |
Correct |
127 ms |
18488 KB |
Output is correct |
70 |
Correct |
143 ms |
18916 KB |
Output is correct |
71 |
Correct |
129 ms |
18404 KB |
Output is correct |
72 |
Correct |
128 ms |
18456 KB |
Output is correct |
73 |
Correct |
158 ms |
24852 KB |
Output is correct |
74 |
Correct |
138 ms |
24924 KB |
Output is correct |
75 |
Correct |
192 ms |
19688 KB |
Output is correct |
76 |
Correct |
124 ms |
19680 KB |
Output is correct |
77 |
Correct |
130 ms |
18404 KB |
Output is correct |
78 |
Correct |
130 ms |
18432 KB |
Output is correct |
79 |
Correct |
140 ms |
18372 KB |
Output is correct |
80 |
Correct |
178 ms |
18404 KB |
Output is correct |
81 |
Correct |
111 ms |
18708 KB |
Output is correct |
82 |
Correct |
131 ms |
18628 KB |
Output is correct |
83 |
Correct |
154 ms |
21272 KB |
Output is correct |
84 |
Correct |
129 ms |
22564 KB |
Output is correct |
85 |
Correct |
151 ms |
22460 KB |
Output is correct |
86 |
Correct |
151 ms |
19000 KB |
Output is correct |
87 |
Correct |
124 ms |
18972 KB |
Output is correct |
88 |
Correct |
127 ms |
18816 KB |
Output is correct |
89 |
Correct |
136 ms |
19228 KB |
Output is correct |
90 |
Correct |
129 ms |
18768 KB |
Output is correct |
91 |
Correct |
122 ms |
18980 KB |
Output is correct |
92 |
Correct |
153 ms |
19112 KB |
Output is correct |
93 |
Correct |
120 ms |
20116 KB |
Output is correct |
94 |
Correct |
121 ms |
21568 KB |
Output is correct |
95 |
Correct |
166 ms |
20604 KB |
Output is correct |
96 |
Correct |
136 ms |
19620 KB |
Output is correct |
97 |
Correct |
115 ms |
18776 KB |
Output is correct |
98 |
Correct |
145 ms |
18628 KB |
Output is correct |
99 |
Correct |
120 ms |
18568 KB |
Output is correct |
100 |
Correct |
126 ms |
19996 KB |
Output is correct |
101 |
Correct |
118 ms |
18864 KB |
Output is correct |
102 |
Correct |
115 ms |
18552 KB |
Output is correct |
103 |
Correct |
124 ms |
18680 KB |
Output is correct |
104 |
Correct |
139 ms |
19132 KB |
Output is correct |
105 |
Correct |
149 ms |
22936 KB |
Output is correct |
106 |
Correct |
101 ms |
19136 KB |
Output is correct |
107 |
Correct |
103 ms |
19132 KB |
Output is correct |
108 |
Correct |
182 ms |
25364 KB |
Output is correct |
109 |
Correct |
106 ms |
19152 KB |
Output is correct |
110 |
Correct |
149 ms |
25620 KB |
Output is correct |
111 |
Correct |
118 ms |
18400 KB |
Output is correct |