#include <bits/stdc++.h>
#define MAX 205000LL
std::vector<int> con[MAX];
std::string valores;
typedef std::pair<int,int> pii;
std::unordered_map<long long,int> mapa;
int explora(long long pos,long long prev){
long long cod = (MAX* pos) + prev;
if(mapa.find(cod)!=mapa.end())return mapa[cod];
int ans=0;
if(valores[pos]=='1')ans=1;
int soma=0;
for(auto&x:con[pos]){
if(x==prev)continue;
soma+=explora(x,pos);
}
if(valores[pos]=='1')--soma;
mapa[cod]=std::max(ans,soma);
return std::max(ans,soma);
}
int N;
int ans=0;
int main()
{
std::cin>>N;
for(int i=1;i!=N;++i){
int a,b;
std::cin>>a>>b;
--a;--b;
con[a].push_back(b);
con[b].push_back(a);
}
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,i);
if(valores[i]=='1')other=std::max(other,b+1);
tot+=b;
}
if(valores[i]=='1'){
--tot;
tot=std::max(tot,1);
}
ans=std::max(ans,tot);
ans=std::max(ans,other);
}
assert(ans);
std::cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
2 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
2 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
5 ms |
5332 KB |
Output is correct |
23 |
Correct |
5 ms |
5332 KB |
Output is correct |
24 |
Correct |
6 ms |
5296 KB |
Output is correct |
25 |
Correct |
5 ms |
5332 KB |
Output is correct |
26 |
Correct |
5 ms |
5268 KB |
Output is correct |
27 |
Correct |
5 ms |
5260 KB |
Output is correct |
28 |
Correct |
5 ms |
5332 KB |
Output is correct |
29 |
Correct |
4 ms |
5396 KB |
Output is correct |
30 |
Correct |
5 ms |
5332 KB |
Output is correct |
31 |
Correct |
6 ms |
5332 KB |
Output is correct |
32 |
Correct |
5 ms |
5332 KB |
Output is correct |
33 |
Correct |
7 ms |
5292 KB |
Output is correct |
34 |
Correct |
5 ms |
5332 KB |
Output is correct |
35 |
Correct |
5 ms |
5332 KB |
Output is correct |
36 |
Correct |
5 ms |
5280 KB |
Output is correct |
37 |
Correct |
30 ms |
5316 KB |
Output is correct |
38 |
Correct |
11 ms |
5316 KB |
Output is correct |
39 |
Correct |
4 ms |
5332 KB |
Output is correct |
40 |
Correct |
5 ms |
5304 KB |
Output is correct |
41 |
Correct |
4 ms |
5332 KB |
Output is correct |
42 |
Correct |
6 ms |
5332 KB |
Output is correct |
43 |
Correct |
5 ms |
5332 KB |
Output is correct |
44 |
Correct |
5 ms |
5332 KB |
Output is correct |
45 |
Correct |
6 ms |
5332 KB |
Output is correct |
46 |
Correct |
6 ms |
5332 KB |
Output is correct |
47 |
Correct |
6 ms |
5332 KB |
Output is correct |
48 |
Correct |
32 ms |
5404 KB |
Output is correct |
49 |
Correct |
15 ms |
5392 KB |
Output is correct |
50 |
Correct |
14 ms |
5332 KB |
Output is correct |
51 |
Correct |
9 ms |
5332 KB |
Output is correct |
52 |
Correct |
5 ms |
5332 KB |
Output is correct |
53 |
Correct |
13 ms |
5368 KB |
Output is correct |
54 |
Correct |
5 ms |
5332 KB |
Output is correct |
55 |
Correct |
6 ms |
5256 KB |
Output is correct |
56 |
Correct |
86 ms |
5404 KB |
Output is correct |
57 |
Correct |
5 ms |
5460 KB |
Output is correct |
58 |
Correct |
90 ms |
5268 KB |
Output is correct |
59 |
Correct |
95 ms |
5440 KB |
Output is correct |
60 |
Correct |
5 ms |
5460 KB |
Output is correct |
61 |
Correct |
88 ms |
5332 KB |
Output is correct |
62 |
Correct |
4 ms |
5460 KB |
Output is correct |
63 |
Correct |
4 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
2 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
5 ms |
5332 KB |
Output is correct |
23 |
Correct |
5 ms |
5332 KB |
Output is correct |
24 |
Correct |
6 ms |
5296 KB |
Output is correct |
25 |
Correct |
5 ms |
5332 KB |
Output is correct |
26 |
Correct |
5 ms |
5268 KB |
Output is correct |
27 |
Correct |
5 ms |
5260 KB |
Output is correct |
28 |
Correct |
5 ms |
5332 KB |
Output is correct |
29 |
Correct |
4 ms |
5396 KB |
Output is correct |
30 |
Correct |
5 ms |
5332 KB |
Output is correct |
31 |
Correct |
6 ms |
5332 KB |
Output is correct |
32 |
Correct |
5 ms |
5332 KB |
Output is correct |
33 |
Correct |
7 ms |
5292 KB |
Output is correct |
34 |
Correct |
5 ms |
5332 KB |
Output is correct |
35 |
Correct |
5 ms |
5332 KB |
Output is correct |
36 |
Correct |
5 ms |
5280 KB |
Output is correct |
37 |
Correct |
30 ms |
5316 KB |
Output is correct |
38 |
Correct |
11 ms |
5316 KB |
Output is correct |
39 |
Correct |
4 ms |
5332 KB |
Output is correct |
40 |
Correct |
5 ms |
5304 KB |
Output is correct |
41 |
Correct |
4 ms |
5332 KB |
Output is correct |
42 |
Correct |
6 ms |
5332 KB |
Output is correct |
43 |
Correct |
5 ms |
5332 KB |
Output is correct |
44 |
Correct |
5 ms |
5332 KB |
Output is correct |
45 |
Correct |
6 ms |
5332 KB |
Output is correct |
46 |
Correct |
6 ms |
5332 KB |
Output is correct |
47 |
Correct |
6 ms |
5332 KB |
Output is correct |
48 |
Correct |
32 ms |
5404 KB |
Output is correct |
49 |
Correct |
15 ms |
5392 KB |
Output is correct |
50 |
Correct |
14 ms |
5332 KB |
Output is correct |
51 |
Correct |
9 ms |
5332 KB |
Output is correct |
52 |
Correct |
5 ms |
5332 KB |
Output is correct |
53 |
Correct |
13 ms |
5368 KB |
Output is correct |
54 |
Correct |
5 ms |
5332 KB |
Output is correct |
55 |
Correct |
6 ms |
5256 KB |
Output is correct |
56 |
Correct |
86 ms |
5404 KB |
Output is correct |
57 |
Correct |
5 ms |
5460 KB |
Output is correct |
58 |
Correct |
90 ms |
5268 KB |
Output is correct |
59 |
Correct |
95 ms |
5440 KB |
Output is correct |
60 |
Correct |
5 ms |
5460 KB |
Output is correct |
61 |
Correct |
88 ms |
5332 KB |
Output is correct |
62 |
Correct |
4 ms |
5460 KB |
Output is correct |
63 |
Correct |
4 ms |
5332 KB |
Output is correct |
64 |
Correct |
516 ms |
30960 KB |
Output is correct |
65 |
Correct |
547 ms |
31128 KB |
Output is correct |
66 |
Correct |
491 ms |
30976 KB |
Output is correct |
67 |
Correct |
479 ms |
30996 KB |
Output is correct |
68 |
Correct |
485 ms |
30956 KB |
Output is correct |
69 |
Correct |
453 ms |
31020 KB |
Output is correct |
70 |
Correct |
483 ms |
30984 KB |
Output is correct |
71 |
Correct |
458 ms |
31024 KB |
Output is correct |
72 |
Correct |
459 ms |
31092 KB |
Output is correct |
73 |
Correct |
497 ms |
43592 KB |
Output is correct |
74 |
Correct |
485 ms |
43428 KB |
Output is correct |
75 |
Correct |
463 ms |
30856 KB |
Output is correct |
76 |
Correct |
477 ms |
30832 KB |
Output is correct |
77 |
Correct |
462 ms |
30852 KB |
Output is correct |
78 |
Correct |
462 ms |
30880 KB |
Output is correct |
79 |
Correct |
467 ms |
30884 KB |
Output is correct |
80 |
Correct |
470 ms |
30840 KB |
Output is correct |
81 |
Execution timed out |
1559 ms |
21448 KB |
Time limit exceeded |
82 |
Halted |
0 ms |
0 KB |
- |