#include<bits/stdc++.h>
using namespace std;
#define int long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define FOR(a,b,c) for(int a=b, __c=c; a<=__c; ++a)
#define FORD(a,b,c) for(int a=b, __c=c; a>=__c; --a)
#define forv(a,b) for(auto &a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define fasty ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define gg exit(0);
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
const int N=2e5+5;
int n;
vector<int> ad[N];
int f[N],dd[N];
int ans=0;
void dfs(int u,int par){
int maxi=0;
forv(v,ad[u]) if(v!=par){
dfs(v,u);
f[u]+=f[v];
maxi=max(maxi,f[v]+1);
}
if(dd[u]){
ans=max(ans,maxi);
f[u]--;
f[u]=max(f[u],1ll);
}
ans=max(ans,f[u]);
}
int32_t main(){
fasty;
cin>>n;
FOR(i,1,n-1){
int u,v;
cin>>u>>v;
ad[u].pb(v); ad[v].pb(u);
}
FOR(i,1,n){
char x; cin>>x; dd[i]=x-'0';
}
dfs(1,0);
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5120 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
5 ms |
5120 KB |
Output is correct |
26 |
Correct |
4 ms |
5120 KB |
Output is correct |
27 |
Correct |
5 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5280 KB |
Output is correct |
30 |
Correct |
5 ms |
5248 KB |
Output is correct |
31 |
Correct |
4 ms |
5248 KB |
Output is correct |
32 |
Correct |
5 ms |
5248 KB |
Output is correct |
33 |
Correct |
4 ms |
5120 KB |
Output is correct |
34 |
Correct |
5 ms |
5224 KB |
Output is correct |
35 |
Correct |
5 ms |
5152 KB |
Output is correct |
36 |
Correct |
4 ms |
5120 KB |
Output is correct |
37 |
Correct |
4 ms |
5120 KB |
Output is correct |
38 |
Correct |
5 ms |
5120 KB |
Output is correct |
39 |
Correct |
4 ms |
5248 KB |
Output is correct |
40 |
Correct |
5 ms |
5120 KB |
Output is correct |
41 |
Correct |
4 ms |
5248 KB |
Output is correct |
42 |
Correct |
4 ms |
5120 KB |
Output is correct |
43 |
Correct |
5 ms |
5120 KB |
Output is correct |
44 |
Correct |
4 ms |
5248 KB |
Output is correct |
45 |
Correct |
4 ms |
5120 KB |
Output is correct |
46 |
Correct |
4 ms |
5120 KB |
Output is correct |
47 |
Correct |
5 ms |
5120 KB |
Output is correct |
48 |
Correct |
4 ms |
5248 KB |
Output is correct |
49 |
Correct |
5 ms |
5248 KB |
Output is correct |
50 |
Correct |
5 ms |
5248 KB |
Output is correct |
51 |
Correct |
4 ms |
5120 KB |
Output is correct |
52 |
Correct |
4 ms |
5120 KB |
Output is correct |
53 |
Correct |
4 ms |
5120 KB |
Output is correct |
54 |
Correct |
5 ms |
5248 KB |
Output is correct |
55 |
Correct |
4 ms |
5120 KB |
Output is correct |
56 |
Correct |
5 ms |
5120 KB |
Output is correct |
57 |
Correct |
4 ms |
5248 KB |
Output is correct |
58 |
Correct |
4 ms |
5120 KB |
Output is correct |
59 |
Correct |
4 ms |
5120 KB |
Output is correct |
60 |
Correct |
5 ms |
5248 KB |
Output is correct |
61 |
Correct |
4 ms |
5120 KB |
Output is correct |
62 |
Correct |
5 ms |
5248 KB |
Output is correct |
63 |
Correct |
4 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5120 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
5 ms |
5120 KB |
Output is correct |
26 |
Correct |
4 ms |
5120 KB |
Output is correct |
27 |
Correct |
5 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5280 KB |
Output is correct |
30 |
Correct |
5 ms |
5248 KB |
Output is correct |
31 |
Correct |
4 ms |
5248 KB |
Output is correct |
32 |
Correct |
5 ms |
5248 KB |
Output is correct |
33 |
Correct |
4 ms |
5120 KB |
Output is correct |
34 |
Correct |
5 ms |
5224 KB |
Output is correct |
35 |
Correct |
5 ms |
5152 KB |
Output is correct |
36 |
Correct |
4 ms |
5120 KB |
Output is correct |
37 |
Correct |
4 ms |
5120 KB |
Output is correct |
38 |
Correct |
5 ms |
5120 KB |
Output is correct |
39 |
Correct |
4 ms |
5248 KB |
Output is correct |
40 |
Correct |
5 ms |
5120 KB |
Output is correct |
41 |
Correct |
4 ms |
5248 KB |
Output is correct |
42 |
Correct |
4 ms |
5120 KB |
Output is correct |
43 |
Correct |
5 ms |
5120 KB |
Output is correct |
44 |
Correct |
4 ms |
5248 KB |
Output is correct |
45 |
Correct |
4 ms |
5120 KB |
Output is correct |
46 |
Correct |
4 ms |
5120 KB |
Output is correct |
47 |
Correct |
5 ms |
5120 KB |
Output is correct |
48 |
Correct |
4 ms |
5248 KB |
Output is correct |
49 |
Correct |
5 ms |
5248 KB |
Output is correct |
50 |
Correct |
5 ms |
5248 KB |
Output is correct |
51 |
Correct |
4 ms |
5120 KB |
Output is correct |
52 |
Correct |
4 ms |
5120 KB |
Output is correct |
53 |
Correct |
4 ms |
5120 KB |
Output is correct |
54 |
Correct |
5 ms |
5248 KB |
Output is correct |
55 |
Correct |
4 ms |
5120 KB |
Output is correct |
56 |
Correct |
5 ms |
5120 KB |
Output is correct |
57 |
Correct |
4 ms |
5248 KB |
Output is correct |
58 |
Correct |
4 ms |
5120 KB |
Output is correct |
59 |
Correct |
4 ms |
5120 KB |
Output is correct |
60 |
Correct |
5 ms |
5248 KB |
Output is correct |
61 |
Correct |
4 ms |
5120 KB |
Output is correct |
62 |
Correct |
5 ms |
5248 KB |
Output is correct |
63 |
Correct |
4 ms |
5120 KB |
Output is correct |
64 |
Correct |
179 ms |
18172 KB |
Output is correct |
65 |
Correct |
179 ms |
18168 KB |
Output is correct |
66 |
Correct |
178 ms |
18172 KB |
Output is correct |
67 |
Correct |
173 ms |
18168 KB |
Output is correct |
68 |
Correct |
175 ms |
18168 KB |
Output is correct |
69 |
Correct |
178 ms |
18296 KB |
Output is correct |
70 |
Correct |
174 ms |
18172 KB |
Output is correct |
71 |
Correct |
172 ms |
18172 KB |
Output is correct |
72 |
Correct |
176 ms |
18424 KB |
Output is correct |
73 |
Correct |
191 ms |
24824 KB |
Output is correct |
74 |
Correct |
193 ms |
24948 KB |
Output is correct |
75 |
Correct |
189 ms |
19448 KB |
Output is correct |
76 |
Correct |
181 ms |
19424 KB |
Output is correct |
77 |
Correct |
179 ms |
18168 KB |
Output is correct |
78 |
Correct |
181 ms |
18208 KB |
Output is correct |
79 |
Correct |
179 ms |
18356 KB |
Output is correct |
80 |
Correct |
192 ms |
18168 KB |
Output is correct |
81 |
Correct |
143 ms |
18156 KB |
Output is correct |
82 |
Correct |
172 ms |
18076 KB |
Output is correct |
83 |
Correct |
185 ms |
21240 KB |
Output is correct |
84 |
Correct |
188 ms |
22520 KB |
Output is correct |
85 |
Correct |
195 ms |
22392 KB |
Output is correct |
86 |
Correct |
180 ms |
19064 KB |
Output is correct |
87 |
Correct |
173 ms |
18808 KB |
Output is correct |
88 |
Correct |
171 ms |
18808 KB |
Output is correct |
89 |
Correct |
171 ms |
18912 KB |
Output is correct |
90 |
Correct |
169 ms |
18680 KB |
Output is correct |
91 |
Correct |
168 ms |
18940 KB |
Output is correct |
92 |
Correct |
173 ms |
19064 KB |
Output is correct |
93 |
Correct |
160 ms |
20076 KB |
Output is correct |
94 |
Correct |
157 ms |
21096 KB |
Output is correct |
95 |
Correct |
151 ms |
20456 KB |
Output is correct |
96 |
Correct |
160 ms |
19320 KB |
Output is correct |
97 |
Correct |
175 ms |
18588 KB |
Output is correct |
98 |
Correct |
163 ms |
18552 KB |
Output is correct |
99 |
Correct |
168 ms |
18296 KB |
Output is correct |
100 |
Correct |
164 ms |
19960 KB |
Output is correct |
101 |
Correct |
167 ms |
18808 KB |
Output is correct |
102 |
Correct |
164 ms |
18424 KB |
Output is correct |
103 |
Correct |
177 ms |
18552 KB |
Output is correct |
104 |
Correct |
104 ms |
17252 KB |
Output is correct |
105 |
Correct |
188 ms |
22936 KB |
Output is correct |
106 |
Correct |
109 ms |
18660 KB |
Output is correct |
107 |
Correct |
107 ms |
18660 KB |
Output is correct |
108 |
Correct |
207 ms |
25208 KB |
Output is correct |
109 |
Correct |
103 ms |
17252 KB |
Output is correct |
110 |
Correct |
195 ms |
25464 KB |
Output is correct |
111 |
Correct |
175 ms |
18296 KB |
Output is correct |