Submission #427596

# Submission time Handle Problem Language Result Execution time Memory
427596 2021-06-14T17:36:18 Z davi_bart Power Plant (JOI20_power) C++17
100 / 100
235 ms 30848 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
int N;
string c;
vector<int> v[200010];
pair<int,int> ans(int pos,int prec){
    vector<pair<int,int> > k;
    for(int x:v[pos]){
        if(x==prec)continue;
        k.pb(ans(x,pos));
    }
    pair<int,int> ma={0,0};//at most 1 in line,most 2 in line
    if(c[pos]=='1'){
        for(auto [a,b]:k){
            ma.fi+=a;
            ma.se=max({ma.se,a+1,b});
        }
        ma.fi--;
        ma.fi=max(ma.fi,(int)1);
    }else{
        for(auto [a,b]:k){
            ma.fi+=a;
            ma.se=max(ma.se,b);
        }
    }
    //cout<<pos<<" "<<ma.fi<<" "<<ma.se<<endl;
    return ma;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin>>c;
    auto k=ans(0,-1);
    cout<<max(k.fi,k.se)<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4936 KB Output is correct
6 Correct 5 ms 4940 KB Output is correct
7 Correct 4 ms 4928 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5016 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 4904 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 5 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4936 KB Output is correct
6 Correct 5 ms 4940 KB Output is correct
7 Correct 4 ms 4928 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5016 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 4904 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 5 ms 4940 KB Output is correct
22 Correct 5 ms 5020 KB Output is correct
23 Correct 5 ms 5068 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 5 ms 5028 KB Output is correct
26 Correct 5 ms 5080 KB Output is correct
27 Correct 5 ms 5068 KB Output is correct
28 Correct 5 ms 5068 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5156 KB Output is correct
31 Correct 5 ms 5068 KB Output is correct
32 Correct 6 ms 5032 KB Output is correct
33 Correct 5 ms 5068 KB Output is correct
34 Correct 6 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 5 ms 5068 KB Output is correct
38 Correct 5 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 5 ms 5068 KB Output is correct
41 Correct 5 ms 5068 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 6 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5028 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 5 ms 5068 KB Output is correct
48 Correct 5 ms 5196 KB Output is correct
49 Correct 5 ms 5156 KB Output is correct
50 Correct 5 ms 5160 KB Output is correct
51 Correct 5 ms 5068 KB Output is correct
52 Correct 5 ms 5028 KB Output is correct
53 Correct 5 ms 5160 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 5 ms 5068 KB Output is correct
56 Correct 4 ms 5104 KB Output is correct
57 Correct 5 ms 5196 KB Output is correct
58 Correct 5 ms 5160 KB Output is correct
59 Correct 5 ms 5132 KB Output is correct
60 Correct 6 ms 5068 KB Output is correct
61 Correct 5 ms 5160 KB Output is correct
62 Correct 6 ms 5136 KB Output is correct
63 Correct 5 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4936 KB Output is correct
6 Correct 5 ms 4940 KB Output is correct
7 Correct 4 ms 4928 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5016 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 4904 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 5 ms 4940 KB Output is correct
22 Correct 5 ms 5020 KB Output is correct
23 Correct 5 ms 5068 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 5 ms 5028 KB Output is correct
26 Correct 5 ms 5080 KB Output is correct
27 Correct 5 ms 5068 KB Output is correct
28 Correct 5 ms 5068 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5156 KB Output is correct
31 Correct 5 ms 5068 KB Output is correct
32 Correct 6 ms 5032 KB Output is correct
33 Correct 5 ms 5068 KB Output is correct
34 Correct 6 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 5 ms 5068 KB Output is correct
38 Correct 5 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 5 ms 5068 KB Output is correct
41 Correct 5 ms 5068 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 6 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5028 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 5 ms 5068 KB Output is correct
48 Correct 5 ms 5196 KB Output is correct
49 Correct 5 ms 5156 KB Output is correct
50 Correct 5 ms 5160 KB Output is correct
51 Correct 5 ms 5068 KB Output is correct
52 Correct 5 ms 5028 KB Output is correct
53 Correct 5 ms 5160 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 5 ms 5068 KB Output is correct
56 Correct 4 ms 5104 KB Output is correct
57 Correct 5 ms 5196 KB Output is correct
58 Correct 5 ms 5160 KB Output is correct
59 Correct 5 ms 5132 KB Output is correct
60 Correct 6 ms 5068 KB Output is correct
61 Correct 5 ms 5160 KB Output is correct
62 Correct 6 ms 5136 KB Output is correct
63 Correct 5 ms 5068 KB Output is correct
64 Correct 174 ms 15420 KB Output is correct
65 Correct 191 ms 15488 KB Output is correct
66 Correct 199 ms 15520 KB Output is correct
67 Correct 179 ms 15420 KB Output is correct
68 Correct 210 ms 15524 KB Output is correct
69 Correct 183 ms 15396 KB Output is correct
70 Correct 188 ms 15432 KB Output is correct
71 Correct 235 ms 15492 KB Output is correct
72 Correct 183 ms 15472 KB Output is correct
73 Correct 204 ms 29588 KB Output is correct
74 Correct 201 ms 29512 KB Output is correct
75 Correct 178 ms 16692 KB Output is correct
76 Correct 194 ms 16740 KB Output is correct
77 Correct 184 ms 15516 KB Output is correct
78 Correct 191 ms 15464 KB Output is correct
79 Correct 184 ms 15416 KB Output is correct
80 Correct 214 ms 15500 KB Output is correct
81 Correct 174 ms 18340 KB Output is correct
82 Correct 194 ms 16268 KB Output is correct
83 Correct 200 ms 21796 KB Output is correct
84 Correct 225 ms 24628 KB Output is correct
85 Correct 208 ms 24212 KB Output is correct
86 Correct 187 ms 17068 KB Output is correct
87 Correct 224 ms 16392 KB Output is correct
88 Correct 162 ms 16400 KB Output is correct
89 Correct 182 ms 16420 KB Output is correct
90 Correct 157 ms 16108 KB Output is correct
91 Correct 171 ms 16440 KB Output is correct
92 Correct 210 ms 16848 KB Output is correct
93 Correct 164 ms 21300 KB Output is correct
94 Correct 166 ms 22420 KB Output is correct
95 Correct 160 ms 20972 KB Output is correct
96 Correct 157 ms 18300 KB Output is correct
97 Correct 158 ms 16092 KB Output is correct
98 Correct 165 ms 15596 KB Output is correct
99 Correct 227 ms 15528 KB Output is correct
100 Correct 188 ms 19644 KB Output is correct
101 Correct 168 ms 16608 KB Output is correct
102 Correct 160 ms 15668 KB Output is correct
103 Correct 175 ms 15732 KB Output is correct
104 Correct 108 ms 22112 KB Output is correct
105 Correct 202 ms 25744 KB Output is correct
106 Correct 123 ms 21796 KB Output is correct
107 Correct 119 ms 21936 KB Output is correct
108 Correct 214 ms 30488 KB Output is correct
109 Correct 117 ms 22064 KB Output is correct
110 Correct 199 ms 30848 KB Output is correct
111 Correct 201 ms 15408 KB Output is correct