Submission #1111076

# Submission time Handle Problem Language Result Execution time Memory
1111076 2024-11-11T12:22:51 Z tymoneq Power Plant (JOI20_power) C++17
100 / 100
106 ms 22868 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int N = 2e5 + 10;

vector<int> adj[N];
int hasPowerPlant[N];
int dp[N];
int ans;
inline void calc(int v, int p)
{
    for (int w : adj[v])
        if (w != p)
            calc(w, v);

    int sum = 0, mx = 0;
    for (int w : adj[v])
        if (w != p)
        {
            sum += dp[w];
            mx = max(dp[w], mx);
        }

    dp[v] = max(hasPowerPlant[v], sum - hasPowerPlant[v]);
    ans = max({ans, sum - hasPowerPlant[v], mx + hasPowerPlant[v]});
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i = 1; i <= n; i++)
    {
        char a;
        cin >> a;
        if (a - '0' == 1)
            hasPowerPlant[i] = 1;
    }

    calc(1, 1);

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6328 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 2 ms 6540 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 4 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 3 ms 6480 KB Output is correct
14 Correct 3 ms 6320 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 3 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 2 ms 6480 KB Output is correct
21 Correct 2 ms 6544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6328 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 2 ms 6540 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 4 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 3 ms 6480 KB Output is correct
14 Correct 3 ms 6320 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 3 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 2 ms 6480 KB Output is correct
21 Correct 2 ms 6544 KB Output is correct
22 Correct 4 ms 6480 KB Output is correct
23 Correct 3 ms 6652 KB Output is correct
24 Correct 3 ms 6480 KB Output is correct
25 Correct 4 ms 6480 KB Output is correct
26 Correct 3 ms 6480 KB Output is correct
27 Correct 3 ms 6480 KB Output is correct
28 Correct 3 ms 6480 KB Output is correct
29 Correct 3 ms 6480 KB Output is correct
30 Correct 3 ms 6480 KB Output is correct
31 Correct 4 ms 6480 KB Output is correct
32 Correct 3 ms 6480 KB Output is correct
33 Correct 3 ms 6480 KB Output is correct
34 Correct 3 ms 6648 KB Output is correct
35 Correct 3 ms 6556 KB Output is correct
36 Correct 3 ms 6480 KB Output is correct
37 Correct 3 ms 6480 KB Output is correct
38 Correct 3 ms 6652 KB Output is correct
39 Correct 4 ms 6480 KB Output is correct
40 Correct 3 ms 6480 KB Output is correct
41 Correct 3 ms 6480 KB Output is correct
42 Correct 3 ms 6628 KB Output is correct
43 Correct 3 ms 6480 KB Output is correct
44 Correct 3 ms 6480 KB Output is correct
45 Correct 3 ms 6544 KB Output is correct
46 Correct 3 ms 6480 KB Output is correct
47 Correct 3 ms 6480 KB Output is correct
48 Correct 3 ms 6480 KB Output is correct
49 Correct 4 ms 6480 KB Output is correct
50 Correct 3 ms 6480 KB Output is correct
51 Correct 3 ms 6480 KB Output is correct
52 Correct 3 ms 6480 KB Output is correct
53 Correct 3 ms 6636 KB Output is correct
54 Correct 3 ms 6652 KB Output is correct
55 Correct 3 ms 6480 KB Output is correct
56 Correct 3 ms 6480 KB Output is correct
57 Correct 3 ms 6648 KB Output is correct
58 Correct 3 ms 6648 KB Output is correct
59 Correct 3 ms 6584 KB Output is correct
60 Correct 3 ms 6648 KB Output is correct
61 Correct 3 ms 6480 KB Output is correct
62 Correct 3 ms 6480 KB Output is correct
63 Correct 3 ms 6652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6328 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 2 ms 6540 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 4 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 3 ms 6480 KB Output is correct
14 Correct 3 ms 6320 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 3 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 2 ms 6480 KB Output is correct
21 Correct 2 ms 6544 KB Output is correct
22 Correct 4 ms 6480 KB Output is correct
23 Correct 3 ms 6652 KB Output is correct
24 Correct 3 ms 6480 KB Output is correct
25 Correct 4 ms 6480 KB Output is correct
26 Correct 3 ms 6480 KB Output is correct
27 Correct 3 ms 6480 KB Output is correct
28 Correct 3 ms 6480 KB Output is correct
29 Correct 3 ms 6480 KB Output is correct
30 Correct 3 ms 6480 KB Output is correct
31 Correct 4 ms 6480 KB Output is correct
32 Correct 3 ms 6480 KB Output is correct
33 Correct 3 ms 6480 KB Output is correct
34 Correct 3 ms 6648 KB Output is correct
35 Correct 3 ms 6556 KB Output is correct
36 Correct 3 ms 6480 KB Output is correct
37 Correct 3 ms 6480 KB Output is correct
38 Correct 3 ms 6652 KB Output is correct
39 Correct 4 ms 6480 KB Output is correct
40 Correct 3 ms 6480 KB Output is correct
41 Correct 3 ms 6480 KB Output is correct
42 Correct 3 ms 6628 KB Output is correct
43 Correct 3 ms 6480 KB Output is correct
44 Correct 3 ms 6480 KB Output is correct
45 Correct 3 ms 6544 KB Output is correct
46 Correct 3 ms 6480 KB Output is correct
47 Correct 3 ms 6480 KB Output is correct
48 Correct 3 ms 6480 KB Output is correct
49 Correct 4 ms 6480 KB Output is correct
50 Correct 3 ms 6480 KB Output is correct
51 Correct 3 ms 6480 KB Output is correct
52 Correct 3 ms 6480 KB Output is correct
53 Correct 3 ms 6636 KB Output is correct
54 Correct 3 ms 6652 KB Output is correct
55 Correct 3 ms 6480 KB Output is correct
56 Correct 3 ms 6480 KB Output is correct
57 Correct 3 ms 6648 KB Output is correct
58 Correct 3 ms 6648 KB Output is correct
59 Correct 3 ms 6584 KB Output is correct
60 Correct 3 ms 6648 KB Output is correct
61 Correct 3 ms 6480 KB Output is correct
62 Correct 3 ms 6480 KB Output is correct
63 Correct 3 ms 6652 KB Output is correct
64 Correct 60 ms 15700 KB Output is correct
65 Correct 56 ms 15720 KB Output is correct
66 Correct 61 ms 15688 KB Output is correct
67 Correct 58 ms 15700 KB Output is correct
68 Correct 63 ms 15688 KB Output is correct
69 Correct 71 ms 15764 KB Output is correct
70 Correct 75 ms 15796 KB Output is correct
71 Correct 59 ms 15760 KB Output is correct
72 Correct 60 ms 15688 KB Output is correct
73 Correct 67 ms 22128 KB Output is correct
74 Correct 65 ms 22344 KB Output is correct
75 Correct 59 ms 15532 KB Output is correct
76 Correct 59 ms 15576 KB Output is correct
77 Correct 61 ms 15564 KB Output is correct
78 Correct 59 ms 15688 KB Output is correct
79 Correct 57 ms 15688 KB Output is correct
80 Correct 57 ms 15628 KB Output is correct
81 Correct 51 ms 15824 KB Output is correct
82 Correct 66 ms 15720 KB Output is correct
83 Correct 66 ms 18248 KB Output is correct
84 Correct 76 ms 19528 KB Output is correct
85 Correct 91 ms 19200 KB Output is correct
86 Correct 59 ms 16464 KB Output is correct
87 Correct 78 ms 16140 KB Output is correct
88 Correct 93 ms 16712 KB Output is correct
89 Correct 81 ms 16672 KB Output is correct
90 Correct 75 ms 16608 KB Output is correct
91 Correct 70 ms 16712 KB Output is correct
92 Correct 63 ms 16828 KB Output is correct
93 Correct 62 ms 17860 KB Output is correct
94 Correct 61 ms 18636 KB Output is correct
95 Correct 60 ms 18116 KB Output is correct
96 Correct 64 ms 17244 KB Output is correct
97 Correct 55 ms 16456 KB Output is correct
98 Correct 60 ms 16200 KB Output is correct
99 Correct 106 ms 15944 KB Output is correct
100 Correct 85 ms 17736 KB Output is correct
101 Correct 76 ms 16612 KB Output is correct
102 Correct 67 ms 16352 KB Output is correct
103 Correct 69 ms 16200 KB Output is correct
104 Correct 58 ms 16412 KB Output is correct
105 Correct 71 ms 20552 KB Output is correct
106 Correct 41 ms 16308 KB Output is correct
107 Correct 44 ms 16324 KB Output is correct
108 Correct 74 ms 22584 KB Output is correct
109 Correct 45 ms 16580 KB Output is correct
110 Correct 72 ms 22868 KB Output is correct
111 Correct 54 ms 15700 KB Output is correct