Submission #866089

# Submission time Handle Problem Language Result Execution time Memory
866089 2023-10-25T11:50:15 Z yanndev Power Plant (JOI20_power) C++17
100 / 100
113 ms 28504 KB
#include <bits/stdc++.h>
using namespace std;

const int MX = 200042;

int isSwitch[MX];
vector<int> adj[MX];
int ans = 0;

int calc(int node, int par) {
    int mx = 0;
    int sum = 0;
    for (auto& x: adj[node]) {
        if (x != par) {
            int v = calc(x, node);
            mx = max(mx, v);
            sum += v;
        }
    }

    ans = max({ans, mx + isSwitch[node], sum - isSwitch[node]});
    int comb = max(mx, isSwitch[node]);
    if (mx > 1)
        comb -= isSwitch[node];
    return max({comb, sum - isSwitch[node]});
}

void solve(int tcId) {
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        isSwitch[i] = c - '0';
    }

    ans = max(ans, calc(0, -1));
    cout << ans << '\n';
}

signed main() {
  	ios::sync_with_stdio(false);
  	cin.tie(nullptr);
    bool multi = false;
    if (!multi) {
        solve(42);
    } else {
        int t;
        cin >> t;
        while (t--)
            solve(t);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 5160 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5164 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 5160 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 5160 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5164 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 5160 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 2 ms 5244 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5172 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 2 ms 5212 KB Output is correct
34 Correct 2 ms 5212 KB Output is correct
35 Correct 2 ms 5212 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5208 KB Output is correct
39 Correct 3 ms 5216 KB Output is correct
40 Correct 3 ms 5216 KB Output is correct
41 Correct 2 ms 5172 KB Output is correct
42 Correct 2 ms 5216 KB Output is correct
43 Correct 2 ms 5216 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5216 KB Output is correct
46 Correct 2 ms 5220 KB Output is correct
47 Correct 2 ms 5220 KB Output is correct
48 Correct 2 ms 5220 KB Output is correct
49 Correct 2 ms 5220 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 3 ms 5460 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5252 KB Output is correct
55 Correct 2 ms 5252 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5212 KB Output is correct
59 Correct 2 ms 5212 KB Output is correct
60 Correct 2 ms 5212 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 5160 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5164 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 5160 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 2 ms 5244 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5172 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 2 ms 5212 KB Output is correct
34 Correct 2 ms 5212 KB Output is correct
35 Correct 2 ms 5212 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5208 KB Output is correct
39 Correct 3 ms 5216 KB Output is correct
40 Correct 3 ms 5216 KB Output is correct
41 Correct 2 ms 5172 KB Output is correct
42 Correct 2 ms 5216 KB Output is correct
43 Correct 2 ms 5216 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5216 KB Output is correct
46 Correct 2 ms 5220 KB Output is correct
47 Correct 2 ms 5220 KB Output is correct
48 Correct 2 ms 5220 KB Output is correct
49 Correct 2 ms 5220 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 3 ms 5460 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5252 KB Output is correct
55 Correct 2 ms 5252 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5212 KB Output is correct
59 Correct 2 ms 5212 KB Output is correct
60 Correct 2 ms 5212 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
64 Correct 58 ms 15016 KB Output is correct
65 Correct 62 ms 14932 KB Output is correct
66 Correct 92 ms 14928 KB Output is correct
67 Correct 57 ms 14932 KB Output is correct
68 Correct 57 ms 14844 KB Output is correct
69 Correct 60 ms 14928 KB Output is correct
70 Correct 113 ms 14864 KB Output is correct
71 Correct 74 ms 14924 KB Output is correct
72 Correct 61 ms 14836 KB Output is correct
73 Correct 76 ms 27624 KB Output is correct
74 Correct 96 ms 27476 KB Output is correct
75 Correct 95 ms 14648 KB Output is correct
76 Correct 87 ms 14892 KB Output is correct
77 Correct 59 ms 14676 KB Output is correct
78 Correct 65 ms 14672 KB Output is correct
79 Correct 56 ms 14772 KB Output is correct
80 Correct 99 ms 14652 KB Output is correct
81 Correct 57 ms 15148 KB Output is correct
82 Correct 64 ms 14988 KB Output is correct
83 Correct 78 ms 19968 KB Output is correct
84 Correct 68 ms 22100 KB Output is correct
85 Correct 85 ms 21840 KB Output is correct
86 Correct 70 ms 16212 KB Output is correct
87 Correct 59 ms 15696 KB Output is correct
88 Correct 58 ms 16208 KB Output is correct
89 Correct 73 ms 15996 KB Output is correct
90 Correct 59 ms 15952 KB Output is correct
91 Correct 57 ms 16212 KB Output is correct
92 Correct 67 ms 16464 KB Output is correct
93 Correct 73 ms 18892 KB Output is correct
94 Correct 85 ms 20424 KB Output is correct
95 Correct 69 ms 19228 KB Output is correct
96 Correct 85 ms 17608 KB Output is correct
97 Correct 72 ms 16040 KB Output is correct
98 Correct 67 ms 15540 KB Output is correct
99 Correct 63 ms 15328 KB Output is correct
100 Correct 60 ms 18516 KB Output is correct
101 Correct 79 ms 16388 KB Output is correct
102 Correct 77 ms 15744 KB Output is correct
103 Correct 55 ms 15408 KB Output is correct
104 Correct 43 ms 15816 KB Output is correct
105 Correct 74 ms 24404 KB Output is correct
106 Correct 44 ms 15552 KB Output is correct
107 Correct 43 ms 15428 KB Output is correct
108 Correct 90 ms 28244 KB Output is correct
109 Correct 45 ms 15560 KB Output is correct
110 Correct 76 ms 28504 KB Output is correct
111 Correct 55 ms 14892 KB Output is correct