답안 #702345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702345 2023-02-23T15:41:31 Z leeh18 Power Plant (JOI20_power) C++17
47 / 100
1500 ms 14152 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    for (auto i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    vector<bool> s(n);
    auto ans = 0;
    for (auto i = 0; i < n; ++i) {
        char c;
        cin >> c;
        s[i] = (c == '1');
        ans += int(s[i]);
    }
    ans = min(ans, 2);
    auto f = [&](auto self, int u, int p) -> int {
        auto sum = 0;
        for (auto v : adj[u]) {
            if (v != p) {
                sum += self(self, v, u);
            }
        }
        return (s[u] ? max(sum - 1, 1) : sum);
    };
    for (auto i = 0; i < n; ++i) {
        ans = max(ans, f(f, i, i));
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 85 ms 440 KB Output is correct
23 Correct 94 ms 436 KB Output is correct
24 Correct 100 ms 340 KB Output is correct
25 Correct 95 ms 432 KB Output is correct
26 Correct 94 ms 444 KB Output is correct
27 Correct 93 ms 432 KB Output is correct
28 Correct 87 ms 432 KB Output is correct
29 Correct 91 ms 468 KB Output is correct
30 Correct 103 ms 464 KB Output is correct
31 Correct 54 ms 428 KB Output is correct
32 Correct 73 ms 432 KB Output is correct
33 Correct 78 ms 428 KB Output is correct
34 Correct 91 ms 432 KB Output is correct
35 Correct 87 ms 340 KB Output is correct
36 Correct 76 ms 428 KB Output is correct
37 Correct 55 ms 340 KB Output is correct
38 Correct 83 ms 340 KB Output is correct
39 Correct 92 ms 472 KB Output is correct
40 Correct 110 ms 468 KB Output is correct
41 Correct 107 ms 460 KB Output is correct
42 Correct 107 ms 448 KB Output is correct
43 Correct 97 ms 340 KB Output is correct
44 Correct 64 ms 340 KB Output is correct
45 Correct 74 ms 468 KB Output is correct
46 Correct 84 ms 468 KB Output is correct
47 Correct 73 ms 340 KB Output is correct
48 Correct 56 ms 476 KB Output is correct
49 Correct 59 ms 480 KB Output is correct
50 Correct 59 ms 424 KB Output is correct
51 Correct 59 ms 460 KB Output is correct
52 Correct 74 ms 328 KB Output is correct
53 Correct 64 ms 468 KB Output is correct
54 Correct 60 ms 468 KB Output is correct
55 Correct 74 ms 444 KB Output is correct
56 Correct 26 ms 456 KB Output is correct
57 Correct 84 ms 468 KB Output is correct
58 Correct 33 ms 340 KB Output is correct
59 Correct 36 ms 468 KB Output is correct
60 Correct 83 ms 432 KB Output is correct
61 Correct 26 ms 340 KB Output is correct
62 Correct 86 ms 508 KB Output is correct
63 Correct 46 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 85 ms 440 KB Output is correct
23 Correct 94 ms 436 KB Output is correct
24 Correct 100 ms 340 KB Output is correct
25 Correct 95 ms 432 KB Output is correct
26 Correct 94 ms 444 KB Output is correct
27 Correct 93 ms 432 KB Output is correct
28 Correct 87 ms 432 KB Output is correct
29 Correct 91 ms 468 KB Output is correct
30 Correct 103 ms 464 KB Output is correct
31 Correct 54 ms 428 KB Output is correct
32 Correct 73 ms 432 KB Output is correct
33 Correct 78 ms 428 KB Output is correct
34 Correct 91 ms 432 KB Output is correct
35 Correct 87 ms 340 KB Output is correct
36 Correct 76 ms 428 KB Output is correct
37 Correct 55 ms 340 KB Output is correct
38 Correct 83 ms 340 KB Output is correct
39 Correct 92 ms 472 KB Output is correct
40 Correct 110 ms 468 KB Output is correct
41 Correct 107 ms 460 KB Output is correct
42 Correct 107 ms 448 KB Output is correct
43 Correct 97 ms 340 KB Output is correct
44 Correct 64 ms 340 KB Output is correct
45 Correct 74 ms 468 KB Output is correct
46 Correct 84 ms 468 KB Output is correct
47 Correct 73 ms 340 KB Output is correct
48 Correct 56 ms 476 KB Output is correct
49 Correct 59 ms 480 KB Output is correct
50 Correct 59 ms 424 KB Output is correct
51 Correct 59 ms 460 KB Output is correct
52 Correct 74 ms 328 KB Output is correct
53 Correct 64 ms 468 KB Output is correct
54 Correct 60 ms 468 KB Output is correct
55 Correct 74 ms 444 KB Output is correct
56 Correct 26 ms 456 KB Output is correct
57 Correct 84 ms 468 KB Output is correct
58 Correct 33 ms 340 KB Output is correct
59 Correct 36 ms 468 KB Output is correct
60 Correct 83 ms 432 KB Output is correct
61 Correct 26 ms 340 KB Output is correct
62 Correct 86 ms 508 KB Output is correct
63 Correct 46 ms 340 KB Output is correct
64 Execution timed out 1586 ms 14152 KB Time limit exceeded
65 Halted 0 ms 0 KB -