Submission #561793

# Submission time Handle Problem Language Result Execution time Memory
561793 2022-05-13T14:14:33 Z 4fecta Power Plant (JOI20_power) C++17
47 / 100
1500 ms 18208 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 200005;

int n, u, v, p[MN], dp[MN], ans;
char c;
vector<int> a[MN];

void dfs(int cur, int par, int rt) {
    int sum = 0;
    for (int nxt : a[cur]) {
        if (nxt == par) continue;
        dfs(nxt, cur, rt);
        sum += dp[nxt];
    }
    if (p[cur] && cur == rt) {
        if (a[rt].size() == 1) dp[cur] = sum + 1;
        else dp[cur] = max(1ll, sum - 1);
    }
    else if (p[cur]) dp[cur] = max(1ll, sum - 1);
    else dp[cur] = sum;
}

int32_t main() {
    boost();

    cin >> n;
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) cin >> c, p[i] = c - '0';
    for (int i = 1; i <= n; i++) {
        dfs(i, 0, i);
        ans = max(ans, dp[i]);
    }
    printf("%lld\n", ans);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 2 ms 5028 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5104 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 2 ms 5028 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5104 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 66 ms 5136 KB Output is correct
23 Correct 71 ms 5140 KB Output is correct
24 Correct 68 ms 5148 KB Output is correct
25 Correct 66 ms 5076 KB Output is correct
26 Correct 67 ms 5136 KB Output is correct
27 Correct 62 ms 5132 KB Output is correct
28 Correct 62 ms 5144 KB Output is correct
29 Correct 85 ms 5204 KB Output is correct
30 Correct 82 ms 5296 KB Output is correct
31 Correct 62 ms 5076 KB Output is correct
32 Correct 60 ms 5148 KB Output is correct
33 Correct 68 ms 5156 KB Output is correct
34 Correct 71 ms 5076 KB Output is correct
35 Correct 68 ms 5036 KB Output is correct
36 Correct 66 ms 5140 KB Output is correct
37 Correct 56 ms 5140 KB Output is correct
38 Correct 61 ms 5144 KB Output is correct
39 Correct 73 ms 5208 KB Output is correct
40 Correct 77 ms 5208 KB Output is correct
41 Correct 73 ms 5204 KB Output is correct
42 Correct 75 ms 5168 KB Output is correct
43 Correct 72 ms 5172 KB Output is correct
44 Correct 67 ms 5176 KB Output is correct
45 Correct 72 ms 5164 KB Output is correct
46 Correct 68 ms 5168 KB Output is correct
47 Correct 60 ms 5088 KB Output is correct
48 Correct 56 ms 5208 KB Output is correct
49 Correct 55 ms 5204 KB Output is correct
50 Correct 56 ms 5164 KB Output is correct
51 Correct 57 ms 5176 KB Output is correct
52 Correct 63 ms 5076 KB Output is correct
53 Correct 58 ms 5204 KB Output is correct
54 Correct 57 ms 5172 KB Output is correct
55 Correct 65 ms 5076 KB Output is correct
56 Correct 31 ms 5076 KB Output is correct
57 Correct 79 ms 5284 KB Output is correct
58 Correct 31 ms 5196 KB Output is correct
59 Correct 30 ms 5076 KB Output is correct
60 Correct 83 ms 5296 KB Output is correct
61 Correct 30 ms 5076 KB Output is correct
62 Correct 80 ms 5204 KB Output is correct
63 Correct 52 ms 5132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 2 ms 5028 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5104 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 66 ms 5136 KB Output is correct
23 Correct 71 ms 5140 KB Output is correct
24 Correct 68 ms 5148 KB Output is correct
25 Correct 66 ms 5076 KB Output is correct
26 Correct 67 ms 5136 KB Output is correct
27 Correct 62 ms 5132 KB Output is correct
28 Correct 62 ms 5144 KB Output is correct
29 Correct 85 ms 5204 KB Output is correct
30 Correct 82 ms 5296 KB Output is correct
31 Correct 62 ms 5076 KB Output is correct
32 Correct 60 ms 5148 KB Output is correct
33 Correct 68 ms 5156 KB Output is correct
34 Correct 71 ms 5076 KB Output is correct
35 Correct 68 ms 5036 KB Output is correct
36 Correct 66 ms 5140 KB Output is correct
37 Correct 56 ms 5140 KB Output is correct
38 Correct 61 ms 5144 KB Output is correct
39 Correct 73 ms 5208 KB Output is correct
40 Correct 77 ms 5208 KB Output is correct
41 Correct 73 ms 5204 KB Output is correct
42 Correct 75 ms 5168 KB Output is correct
43 Correct 72 ms 5172 KB Output is correct
44 Correct 67 ms 5176 KB Output is correct
45 Correct 72 ms 5164 KB Output is correct
46 Correct 68 ms 5168 KB Output is correct
47 Correct 60 ms 5088 KB Output is correct
48 Correct 56 ms 5208 KB Output is correct
49 Correct 55 ms 5204 KB Output is correct
50 Correct 56 ms 5164 KB Output is correct
51 Correct 57 ms 5176 KB Output is correct
52 Correct 63 ms 5076 KB Output is correct
53 Correct 58 ms 5204 KB Output is correct
54 Correct 57 ms 5172 KB Output is correct
55 Correct 65 ms 5076 KB Output is correct
56 Correct 31 ms 5076 KB Output is correct
57 Correct 79 ms 5284 KB Output is correct
58 Correct 31 ms 5196 KB Output is correct
59 Correct 30 ms 5076 KB Output is correct
60 Correct 83 ms 5296 KB Output is correct
61 Correct 30 ms 5076 KB Output is correct
62 Correct 80 ms 5204 KB Output is correct
63 Correct 52 ms 5132 KB Output is correct
64 Execution timed out 1586 ms 18208 KB Time limit exceeded
65 Halted 0 ms 0 KB -