#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
vector<int>a[200009];
int f[200009];
string s;
int ans=0;
void dfs(int u,int par){
if (s[u]=='1'){
f[u]=1;
}
int sum=0;
for (auto v:a[u]){
if (v==par)continue;
dfs(v,u);
if (s[u]=='1'){
ans=max(ans,f[v]+1);
}
sum+=f[v];
}
if (s[u]=='1')sum--;
f[u]=max(f[u],sum);
ans=max(ans,f[u]);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
int n;
cin>>n;
for1(i,1,n-1){
int u,v;
cin>>u>>v;
a[u].pb(v);
a[v].pb(u);
}
cin>>s;
s=" "+s;
dfs(1,0);
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
5024 KB |
Output is correct |
7 |
Correct |
2 ms |
5020 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
5020 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
5024 KB |
Output is correct |
7 |
Correct |
2 ms |
5020 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
5020 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5040 KB |
Output is correct |
28 |
Correct |
3 ms |
5052 KB |
Output is correct |
29 |
Correct |
3 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5164 KB |
Output is correct |
31 |
Correct |
4 ms |
5036 KB |
Output is correct |
32 |
Correct |
3 ms |
5036 KB |
Output is correct |
33 |
Correct |
3 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5032 KB |
Output is correct |
38 |
Correct |
3 ms |
5032 KB |
Output is correct |
39 |
Correct |
3 ms |
5076 KB |
Output is correct |
40 |
Correct |
3 ms |
5080 KB |
Output is correct |
41 |
Correct |
3 ms |
5084 KB |
Output is correct |
42 |
Correct |
3 ms |
5036 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
3 ms |
5040 KB |
Output is correct |
48 |
Correct |
3 ms |
5160 KB |
Output is correct |
49 |
Correct |
3 ms |
5160 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
4 ms |
5016 KB |
Output is correct |
53 |
Correct |
3 ms |
5160 KB |
Output is correct |
54 |
Correct |
3 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5204 KB |
Output is correct |
56 |
Correct |
4 ms |
5076 KB |
Output is correct |
57 |
Correct |
4 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
3 ms |
5168 KB |
Output is correct |
61 |
Correct |
3 ms |
5036 KB |
Output is correct |
62 |
Correct |
3 ms |
5160 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
5024 KB |
Output is correct |
7 |
Correct |
2 ms |
5020 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
5020 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5040 KB |
Output is correct |
28 |
Correct |
3 ms |
5052 KB |
Output is correct |
29 |
Correct |
3 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5164 KB |
Output is correct |
31 |
Correct |
4 ms |
5036 KB |
Output is correct |
32 |
Correct |
3 ms |
5036 KB |
Output is correct |
33 |
Correct |
3 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5032 KB |
Output is correct |
38 |
Correct |
3 ms |
5032 KB |
Output is correct |
39 |
Correct |
3 ms |
5076 KB |
Output is correct |
40 |
Correct |
3 ms |
5080 KB |
Output is correct |
41 |
Correct |
3 ms |
5084 KB |
Output is correct |
42 |
Correct |
3 ms |
5036 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
3 ms |
5040 KB |
Output is correct |
48 |
Correct |
3 ms |
5160 KB |
Output is correct |
49 |
Correct |
3 ms |
5160 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
4 ms |
5016 KB |
Output is correct |
53 |
Correct |
3 ms |
5160 KB |
Output is correct |
54 |
Correct |
3 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5204 KB |
Output is correct |
56 |
Correct |
4 ms |
5076 KB |
Output is correct |
57 |
Correct |
4 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
3 ms |
5168 KB |
Output is correct |
61 |
Correct |
3 ms |
5036 KB |
Output is correct |
62 |
Correct |
3 ms |
5160 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
115 ms |
15156 KB |
Output is correct |
65 |
Correct |
72 ms |
15264 KB |
Output is correct |
66 |
Correct |
77 ms |
15128 KB |
Output is correct |
67 |
Correct |
66 ms |
15200 KB |
Output is correct |
68 |
Correct |
70 ms |
15156 KB |
Output is correct |
69 |
Correct |
92 ms |
15092 KB |
Output is correct |
70 |
Correct |
75 ms |
15196 KB |
Output is correct |
71 |
Correct |
66 ms |
15116 KB |
Output is correct |
72 |
Correct |
64 ms |
15204 KB |
Output is correct |
73 |
Correct |
109 ms |
27768 KB |
Output is correct |
74 |
Correct |
94 ms |
27748 KB |
Output is correct |
75 |
Correct |
73 ms |
15068 KB |
Output is correct |
76 |
Correct |
66 ms |
14988 KB |
Output is correct |
77 |
Correct |
93 ms |
15068 KB |
Output is correct |
78 |
Correct |
92 ms |
15024 KB |
Output is correct |
79 |
Correct |
74 ms |
15084 KB |
Output is correct |
80 |
Correct |
67 ms |
14996 KB |
Output is correct |
81 |
Correct |
97 ms |
15536 KB |
Output is correct |
82 |
Correct |
86 ms |
15208 KB |
Output is correct |
83 |
Correct |
84 ms |
20216 KB |
Output is correct |
84 |
Correct |
77 ms |
22320 KB |
Output is correct |
85 |
Correct |
87 ms |
22084 KB |
Output is correct |
86 |
Correct |
76 ms |
16520 KB |
Output is correct |
87 |
Correct |
90 ms |
15964 KB |
Output is correct |
88 |
Correct |
74 ms |
16388 KB |
Output is correct |
89 |
Correct |
75 ms |
16428 KB |
Output is correct |
90 |
Correct |
68 ms |
16220 KB |
Output is correct |
91 |
Correct |
112 ms |
16424 KB |
Output is correct |
92 |
Correct |
73 ms |
16764 KB |
Output is correct |
93 |
Correct |
90 ms |
19096 KB |
Output is correct |
94 |
Correct |
72 ms |
20840 KB |
Output is correct |
95 |
Correct |
91 ms |
19572 KB |
Output is correct |
96 |
Correct |
86 ms |
17728 KB |
Output is correct |
97 |
Correct |
66 ms |
16160 KB |
Output is correct |
98 |
Correct |
84 ms |
15644 KB |
Output is correct |
99 |
Correct |
66 ms |
15416 KB |
Output is correct |
100 |
Correct |
87 ms |
18704 KB |
Output is correct |
101 |
Correct |
85 ms |
16648 KB |
Output is correct |
102 |
Correct |
66 ms |
15956 KB |
Output is correct |
103 |
Correct |
70 ms |
15696 KB |
Output is correct |
104 |
Correct |
49 ms |
16064 KB |
Output is correct |
105 |
Correct |
106 ms |
24536 KB |
Output is correct |
106 |
Correct |
52 ms |
15936 KB |
Output is correct |
107 |
Correct |
45 ms |
15936 KB |
Output is correct |
108 |
Correct |
83 ms |
28552 KB |
Output is correct |
109 |
Correct |
46 ms |
15964 KB |
Output is correct |
110 |
Correct |
94 ms |
28836 KB |
Output is correct |
111 |
Correct |
64 ms |
15072 KB |
Output is correct |