Submission #582050

# Submission time Handle Problem Language Result Execution time Memory
582050 2022-06-23T10:24:19 Z Vanilla Power Plant (JOI20_power) C++17
100 / 100
258 ms 28056 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e5 + 2;
int n;
int ans = 0;
vector <int> ad [maxn];
string type;

int dp (int u, int p) {
    int rs0 = 0, rs1 = 0;
    for (int v: ad[u]) {
        if (v == p) continue;
        int k = dp(v, u);
        rs0+=k;
        rs1=max(rs1, k);
    }
    if (type[u] == '1') {
        ans = max({ans, rs1 + 1, rs0 - 1, 1});
        return max(rs0 - 1, 1);
    }
    ans = max(ans, rs0);
    return rs0;
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        ad[x].push_back(y);
        ad[y].push_back(x);
    }
    cin >> type;
    dp(0, -1);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4996 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4904 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4996 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4996 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4996 KB Output is correct
21 Correct 3 ms 4988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4996 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4904 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4996 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4996 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4996 KB Output is correct
21 Correct 3 ms 4988 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 6 ms 5012 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 5 ms 5012 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 5 ms 5076 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5012 KB Output is correct
37 Correct 5 ms 5016 KB Output is correct
38 Correct 5 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5020 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 4 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 5 ms 5012 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 4 ms 5076 KB Output is correct
50 Correct 5 ms 5076 KB Output is correct
51 Correct 5 ms 5076 KB Output is correct
52 Correct 5 ms 5076 KB Output is correct
53 Correct 4 ms 5076 KB Output is correct
54 Correct 5 ms 5020 KB Output is correct
55 Correct 4 ms 5016 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5020 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5076 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 4 ms 5076 KB Output is correct
63 Correct 4 ms 5012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4996 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4904 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4996 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4996 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4996 KB Output is correct
21 Correct 3 ms 4988 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 6 ms 5012 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 5 ms 5012 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 5 ms 5076 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5012 KB Output is correct
37 Correct 5 ms 5016 KB Output is correct
38 Correct 5 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5020 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 4 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 5 ms 5012 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 4 ms 5076 KB Output is correct
50 Correct 5 ms 5076 KB Output is correct
51 Correct 5 ms 5076 KB Output is correct
52 Correct 5 ms 5076 KB Output is correct
53 Correct 4 ms 5076 KB Output is correct
54 Correct 5 ms 5020 KB Output is correct
55 Correct 4 ms 5016 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5020 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5076 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 4 ms 5076 KB Output is correct
63 Correct 4 ms 5012 KB Output is correct
64 Correct 222 ms 14356 KB Output is correct
65 Correct 198 ms 14432 KB Output is correct
66 Correct 188 ms 14404 KB Output is correct
67 Correct 219 ms 14400 KB Output is correct
68 Correct 204 ms 14416 KB Output is correct
69 Correct 189 ms 14516 KB Output is correct
70 Correct 226 ms 14400 KB Output is correct
71 Correct 213 ms 14356 KB Output is correct
72 Correct 258 ms 14424 KB Output is correct
73 Correct 238 ms 26912 KB Output is correct
74 Correct 237 ms 26916 KB Output is correct
75 Correct 224 ms 14268 KB Output is correct
76 Correct 196 ms 14316 KB Output is correct
77 Correct 210 ms 14288 KB Output is correct
78 Correct 213 ms 14272 KB Output is correct
79 Correct 214 ms 14328 KB Output is correct
80 Correct 226 ms 14348 KB Output is correct
81 Correct 186 ms 14772 KB Output is correct
82 Correct 191 ms 14504 KB Output is correct
83 Correct 213 ms 19452 KB Output is correct
84 Correct 205 ms 21536 KB Output is correct
85 Correct 228 ms 21344 KB Output is correct
86 Correct 205 ms 15704 KB Output is correct
87 Correct 192 ms 15064 KB Output is correct
88 Correct 197 ms 15552 KB Output is correct
89 Correct 242 ms 15572 KB Output is correct
90 Correct 184 ms 15356 KB Output is correct
91 Correct 212 ms 15644 KB Output is correct
92 Correct 255 ms 15980 KB Output is correct
93 Correct 177 ms 18248 KB Output is correct
94 Correct 199 ms 20092 KB Output is correct
95 Correct 206 ms 18716 KB Output is correct
96 Correct 191 ms 16908 KB Output is correct
97 Correct 195 ms 15356 KB Output is correct
98 Correct 204 ms 14964 KB Output is correct
99 Correct 208 ms 14844 KB Output is correct
100 Correct 241 ms 17916 KB Output is correct
101 Correct 210 ms 15844 KB Output is correct
102 Correct 178 ms 15072 KB Output is correct
103 Correct 209 ms 15060 KB Output is correct
104 Correct 166 ms 15296 KB Output is correct
105 Correct 217 ms 23764 KB Output is correct
106 Correct 154 ms 15092 KB Output is correct
107 Correct 201 ms 15168 KB Output is correct
108 Correct 226 ms 27748 KB Output is correct
109 Correct 160 ms 15256 KB Output is correct
110 Correct 257 ms 28056 KB Output is correct
111 Correct 216 ms 14324 KB Output is correct