#include <bits/stdc++.h>
#define MAX 505000LL
typedef std::pair<int,int> pii;
std::vector<pii> con[MAX];
std::string valores;
bool existe[MAX*2];
int tab[MAX*2];
int count=0;
int explora(long long pos,long long prev,int ind){
if(existe[ind])return tab[ind];
existe[ind]=true;
count++;
int ans=0;
if(valores[pos]=='1')ans=1;
int soma=0;
for(auto&x:con[pos]){
if(x.first==prev)continue;
soma+=explora(x.first,pos,x.second);
}
if(valores[pos]=='1')--soma;
return tab[ind]=std::max(ans,soma);
}
int N;
int ans=0;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int cur=2;
std::cin>>N;
for(int i=1;i!=N;++i){
int a,b;
std::cin>>a>>b;
--a;--b;
con[a].push_back({b,cur});++cur;
con[b].push_back({a,cur});++cur;
}
std::cin>>valores;
for(int i=0;i!=N;++i){
int tot=0;
int other=0;
for(auto&x:con[i]){
int b = explora(x.first,i,x.second);
if(valores[i]=='1')other=std::max(other,b+1);
tot+=b;
}
assert(count<MAX*2);
if(valores[i]=='1'){
--tot;
tot=std::max(tot,1);
}
ans=std::max(ans,tot);
ans=std::max(ans,other);
}
std::cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12116 KB |
Output is correct |
2 |
Correct |
7 ms |
12116 KB |
Output is correct |
3 |
Correct |
7 ms |
12116 KB |
Output is correct |
4 |
Correct |
8 ms |
12116 KB |
Output is correct |
5 |
Correct |
8 ms |
12116 KB |
Output is correct |
6 |
Correct |
6 ms |
12116 KB |
Output is correct |
7 |
Correct |
6 ms |
12116 KB |
Output is correct |
8 |
Correct |
6 ms |
12116 KB |
Output is correct |
9 |
Correct |
6 ms |
12116 KB |
Output is correct |
10 |
Correct |
6 ms |
12116 KB |
Output is correct |
11 |
Correct |
6 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
12192 KB |
Output is correct |
13 |
Correct |
7 ms |
12116 KB |
Output is correct |
14 |
Correct |
6 ms |
12192 KB |
Output is correct |
15 |
Correct |
7 ms |
12188 KB |
Output is correct |
16 |
Correct |
7 ms |
12084 KB |
Output is correct |
17 |
Correct |
7 ms |
12128 KB |
Output is correct |
18 |
Correct |
7 ms |
12100 KB |
Output is correct |
19 |
Correct |
8 ms |
12140 KB |
Output is correct |
20 |
Correct |
8 ms |
12116 KB |
Output is correct |
21 |
Correct |
7 ms |
12108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12116 KB |
Output is correct |
2 |
Correct |
7 ms |
12116 KB |
Output is correct |
3 |
Correct |
7 ms |
12116 KB |
Output is correct |
4 |
Correct |
8 ms |
12116 KB |
Output is correct |
5 |
Correct |
8 ms |
12116 KB |
Output is correct |
6 |
Correct |
6 ms |
12116 KB |
Output is correct |
7 |
Correct |
6 ms |
12116 KB |
Output is correct |
8 |
Correct |
6 ms |
12116 KB |
Output is correct |
9 |
Correct |
6 ms |
12116 KB |
Output is correct |
10 |
Correct |
6 ms |
12116 KB |
Output is correct |
11 |
Correct |
6 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
12192 KB |
Output is correct |
13 |
Correct |
7 ms |
12116 KB |
Output is correct |
14 |
Correct |
6 ms |
12192 KB |
Output is correct |
15 |
Correct |
7 ms |
12188 KB |
Output is correct |
16 |
Correct |
7 ms |
12084 KB |
Output is correct |
17 |
Correct |
7 ms |
12128 KB |
Output is correct |
18 |
Correct |
7 ms |
12100 KB |
Output is correct |
19 |
Correct |
8 ms |
12140 KB |
Output is correct |
20 |
Correct |
8 ms |
12116 KB |
Output is correct |
21 |
Correct |
7 ms |
12108 KB |
Output is correct |
22 |
Correct |
8 ms |
12244 KB |
Output is correct |
23 |
Correct |
6 ms |
12240 KB |
Output is correct |
24 |
Correct |
7 ms |
12188 KB |
Output is correct |
25 |
Correct |
7 ms |
12244 KB |
Output is correct |
26 |
Correct |
8 ms |
12256 KB |
Output is correct |
27 |
Correct |
8 ms |
12244 KB |
Output is correct |
28 |
Correct |
8 ms |
12244 KB |
Output is correct |
29 |
Correct |
7 ms |
12372 KB |
Output is correct |
30 |
Correct |
7 ms |
12372 KB |
Output is correct |
31 |
Correct |
7 ms |
12244 KB |
Output is correct |
32 |
Correct |
7 ms |
12244 KB |
Output is correct |
33 |
Correct |
8 ms |
12220 KB |
Output is correct |
34 |
Correct |
8 ms |
12196 KB |
Output is correct |
35 |
Correct |
8 ms |
12288 KB |
Output is correct |
36 |
Correct |
9 ms |
12244 KB |
Output is correct |
37 |
Correct |
9 ms |
12244 KB |
Output is correct |
38 |
Correct |
7 ms |
12244 KB |
Output is correct |
39 |
Correct |
7 ms |
12308 KB |
Output is correct |
40 |
Correct |
7 ms |
12244 KB |
Output is correct |
41 |
Correct |
7 ms |
12244 KB |
Output is correct |
42 |
Correct |
8 ms |
12244 KB |
Output is correct |
43 |
Correct |
7 ms |
12244 KB |
Output is correct |
44 |
Correct |
7 ms |
12256 KB |
Output is correct |
45 |
Correct |
7 ms |
12244 KB |
Output is correct |
46 |
Correct |
7 ms |
12244 KB |
Output is correct |
47 |
Correct |
9 ms |
12244 KB |
Output is correct |
48 |
Correct |
9 ms |
12420 KB |
Output is correct |
49 |
Correct |
8 ms |
12380 KB |
Output is correct |
50 |
Correct |
8 ms |
12244 KB |
Output is correct |
51 |
Correct |
10 ms |
12244 KB |
Output is correct |
52 |
Correct |
7 ms |
12244 KB |
Output is correct |
53 |
Correct |
8 ms |
12244 KB |
Output is correct |
54 |
Correct |
8 ms |
12244 KB |
Output is correct |
55 |
Correct |
7 ms |
12244 KB |
Output is correct |
56 |
Correct |
12 ms |
12244 KB |
Output is correct |
57 |
Correct |
8 ms |
12364 KB |
Output is correct |
58 |
Correct |
13 ms |
12316 KB |
Output is correct |
59 |
Correct |
12 ms |
12244 KB |
Output is correct |
60 |
Correct |
8 ms |
12348 KB |
Output is correct |
61 |
Correct |
13 ms |
12244 KB |
Output is correct |
62 |
Correct |
7 ms |
12372 KB |
Output is correct |
63 |
Correct |
7 ms |
12264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12116 KB |
Output is correct |
2 |
Correct |
7 ms |
12116 KB |
Output is correct |
3 |
Correct |
7 ms |
12116 KB |
Output is correct |
4 |
Correct |
8 ms |
12116 KB |
Output is correct |
5 |
Correct |
8 ms |
12116 KB |
Output is correct |
6 |
Correct |
6 ms |
12116 KB |
Output is correct |
7 |
Correct |
6 ms |
12116 KB |
Output is correct |
8 |
Correct |
6 ms |
12116 KB |
Output is correct |
9 |
Correct |
6 ms |
12116 KB |
Output is correct |
10 |
Correct |
6 ms |
12116 KB |
Output is correct |
11 |
Correct |
6 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
12192 KB |
Output is correct |
13 |
Correct |
7 ms |
12116 KB |
Output is correct |
14 |
Correct |
6 ms |
12192 KB |
Output is correct |
15 |
Correct |
7 ms |
12188 KB |
Output is correct |
16 |
Correct |
7 ms |
12084 KB |
Output is correct |
17 |
Correct |
7 ms |
12128 KB |
Output is correct |
18 |
Correct |
7 ms |
12100 KB |
Output is correct |
19 |
Correct |
8 ms |
12140 KB |
Output is correct |
20 |
Correct |
8 ms |
12116 KB |
Output is correct |
21 |
Correct |
7 ms |
12108 KB |
Output is correct |
22 |
Correct |
8 ms |
12244 KB |
Output is correct |
23 |
Correct |
6 ms |
12240 KB |
Output is correct |
24 |
Correct |
7 ms |
12188 KB |
Output is correct |
25 |
Correct |
7 ms |
12244 KB |
Output is correct |
26 |
Correct |
8 ms |
12256 KB |
Output is correct |
27 |
Correct |
8 ms |
12244 KB |
Output is correct |
28 |
Correct |
8 ms |
12244 KB |
Output is correct |
29 |
Correct |
7 ms |
12372 KB |
Output is correct |
30 |
Correct |
7 ms |
12372 KB |
Output is correct |
31 |
Correct |
7 ms |
12244 KB |
Output is correct |
32 |
Correct |
7 ms |
12244 KB |
Output is correct |
33 |
Correct |
8 ms |
12220 KB |
Output is correct |
34 |
Correct |
8 ms |
12196 KB |
Output is correct |
35 |
Correct |
8 ms |
12288 KB |
Output is correct |
36 |
Correct |
9 ms |
12244 KB |
Output is correct |
37 |
Correct |
9 ms |
12244 KB |
Output is correct |
38 |
Correct |
7 ms |
12244 KB |
Output is correct |
39 |
Correct |
7 ms |
12308 KB |
Output is correct |
40 |
Correct |
7 ms |
12244 KB |
Output is correct |
41 |
Correct |
7 ms |
12244 KB |
Output is correct |
42 |
Correct |
8 ms |
12244 KB |
Output is correct |
43 |
Correct |
7 ms |
12244 KB |
Output is correct |
44 |
Correct |
7 ms |
12256 KB |
Output is correct |
45 |
Correct |
7 ms |
12244 KB |
Output is correct |
46 |
Correct |
7 ms |
12244 KB |
Output is correct |
47 |
Correct |
9 ms |
12244 KB |
Output is correct |
48 |
Correct |
9 ms |
12420 KB |
Output is correct |
49 |
Correct |
8 ms |
12380 KB |
Output is correct |
50 |
Correct |
8 ms |
12244 KB |
Output is correct |
51 |
Correct |
10 ms |
12244 KB |
Output is correct |
52 |
Correct |
7 ms |
12244 KB |
Output is correct |
53 |
Correct |
8 ms |
12244 KB |
Output is correct |
54 |
Correct |
8 ms |
12244 KB |
Output is correct |
55 |
Correct |
7 ms |
12244 KB |
Output is correct |
56 |
Correct |
12 ms |
12244 KB |
Output is correct |
57 |
Correct |
8 ms |
12364 KB |
Output is correct |
58 |
Correct |
13 ms |
12316 KB |
Output is correct |
59 |
Correct |
12 ms |
12244 KB |
Output is correct |
60 |
Correct |
8 ms |
12348 KB |
Output is correct |
61 |
Correct |
13 ms |
12244 KB |
Output is correct |
62 |
Correct |
7 ms |
12372 KB |
Output is correct |
63 |
Correct |
7 ms |
12264 KB |
Output is correct |
64 |
Correct |
210 ms |
21880 KB |
Output is correct |
65 |
Correct |
173 ms |
21772 KB |
Output is correct |
66 |
Correct |
233 ms |
21832 KB |
Output is correct |
67 |
Correct |
176 ms |
21744 KB |
Output is correct |
68 |
Correct |
164 ms |
21756 KB |
Output is correct |
69 |
Correct |
181 ms |
21816 KB |
Output is correct |
70 |
Correct |
199 ms |
21804 KB |
Output is correct |
71 |
Correct |
160 ms |
21812 KB |
Output is correct |
72 |
Correct |
163 ms |
21720 KB |
Output is correct |
73 |
Correct |
236 ms |
35924 KB |
Output is correct |
74 |
Correct |
178 ms |
35884 KB |
Output is correct |
75 |
Correct |
166 ms |
23020 KB |
Output is correct |
76 |
Correct |
198 ms |
22984 KB |
Output is correct |
77 |
Correct |
173 ms |
21768 KB |
Output is correct |
78 |
Correct |
173 ms |
21728 KB |
Output is correct |
79 |
Correct |
211 ms |
21776 KB |
Output is correct |
80 |
Correct |
158 ms |
21720 KB |
Output is correct |
81 |
Execution timed out |
1585 ms |
21808 KB |
Time limit exceeded |
82 |
Halted |
0 ms |
0 KB |
- |