답안 #1064498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064498 2024-08-18T13:29:43 Z aufan Power Plant (JOI20_power) C++17
100 / 100
95 ms 39252 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int n;
        cin >> n;

        vector<vector<int>> v(n + 1);
        for (int i = 0; i < n - 1; i++) {
                int a, b;
                cin >> a >> b;

                v[a].push_back(b);
                v[b].push_back(a);
        }

        vector<int> ok(n + 1);
        for (int i = 1; i <= n; i++) {
                char c;
                cin >> c;

                ok[i] = (c == '1');
        }

        int ans = 0;
        vector<int> dp(n + 1);

        function<void(int, int)> dfs = [&](int x, int p) {
                dp[x] = ok[x];

                int cur = -ok[x];
                for (auto z : v[x]) {
                        if (z == p) continue;

                        dfs(z, x);

                        ans = max(ans, dp[z] + ok[x]);
                        cur += dp[z];
                }

                dp[x] = max(dp[x], cur);
                ans = max(ans, dp[x]);
        };

        dfs(1, 1);

        cout << ans << '\n';
        
        return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 584 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 588 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 592 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 600 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 580 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 584 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 588 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 592 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 600 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 580 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 600 KB Output is correct
64 Correct 73 ms 18264 KB Output is correct
65 Correct 70 ms 18256 KB Output is correct
66 Correct 73 ms 18264 KB Output is correct
67 Correct 74 ms 18264 KB Output is correct
68 Correct 74 ms 18340 KB Output is correct
69 Correct 71 ms 18144 KB Output is correct
70 Correct 71 ms 18256 KB Output is correct
71 Correct 66 ms 18152 KB Output is correct
72 Correct 65 ms 18260 KB Output is correct
73 Correct 85 ms 37460 KB Output is correct
74 Correct 88 ms 37460 KB Output is correct
75 Correct 65 ms 19536 KB Output is correct
76 Correct 66 ms 19584 KB Output is correct
77 Correct 73 ms 18340 KB Output is correct
78 Correct 71 ms 18256 KB Output is correct
79 Correct 86 ms 18260 KB Output is correct
80 Correct 66 ms 18312 KB Output is correct
81 Correct 63 ms 18184 KB Output is correct
82 Correct 70 ms 18124 KB Output is correct
83 Correct 68 ms 26516 KB Output is correct
84 Correct 88 ms 29764 KB Output is correct
85 Correct 93 ms 29452 KB Output is correct
86 Correct 67 ms 20308 KB Output is correct
87 Correct 79 ms 19444 KB Output is correct
88 Correct 64 ms 19540 KB Output is correct
89 Correct 64 ms 19536 KB Output is correct
90 Correct 67 ms 19284 KB Output is correct
91 Correct 68 ms 19536 KB Output is correct
92 Correct 66 ms 20048 KB Output is correct
93 Correct 62 ms 23888 KB Output is correct
94 Correct 70 ms 26564 KB Output is correct
95 Correct 63 ms 24516 KB Output is correct
96 Correct 63 ms 21584 KB Output is correct
97 Correct 59 ms 19280 KB Output is correct
98 Correct 63 ms 18512 KB Output is correct
99 Correct 61 ms 18428 KB Output is correct
100 Correct 80 ms 23348 KB Output is correct
101 Correct 64 ms 19796 KB Output is correct
102 Correct 60 ms 18612 KB Output is correct
103 Correct 66 ms 18512 KB Output is correct
104 Correct 43 ms 18880 KB Output is correct
105 Correct 83 ms 32600 KB Output is correct
106 Correct 45 ms 18628 KB Output is correct
107 Correct 49 ms 18492 KB Output is correct
108 Correct 95 ms 38788 KB Output is correct
109 Correct 45 ms 18692 KB Output is correct
110 Correct 88 ms 39252 KB Output is correct
111 Correct 57 ms 18148 KB Output is correct