Submission #723534

# Submission time Handle Problem Language Result Execution time Memory
723534 2023-04-14T04:06:22 Z t6twotwo Village (BOI20_village) C++17
50 / 100
102 ms 23156 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 1; i < n; i++) {
        int x; cin >> x; x--;
        int y; cin >> y; y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    vector<int> a(n);
    iota(a.begin(), a.end(), 0);
    int ans = 0;
    auto dfs = [&](auto dfs, int x, int p) -> bool {
        vector<int> b;
        for (int y : adj[x]) {
            if (y != p) {
                if (dfs(dfs, y, x)) {
                    b.push_back(y);
                }
            }
        }
        if (b.empty()) {
            return 1;
        }
        ans += b.size() * 2;
        if (b.size() % 2 == 1) {
            swap(a[x], a[b[0]]);
            for (int i = 1; i < b.size(); i += 2) {
                swap(a[b[i]], a[b[i + 1]]);
            }
        } else {
            swap(a[x], a[b[0]]);
            swap(a[x], a[b[1]]);
            for (int i = 2; i < b.size(); i += 2) {
                swap(a[b[i]], a[b[i + 1]]);
            }
        }
        return 0;
    };
    if (dfs(dfs, 0, -1)) {
        swap(a[0], a[adj[0][0]]);
        ans += 2;
    }
    cout << ans << " " << 0 << "\n";
    for (int i = 0; i < n; i++) {
        cout << a[i] + 1 << " \n"[i == n - 1];
    }
    for (int i = 0; i < n; i++) {
        cout << 1 << " \n"[i == n - 1];
    }
    return 6/22;
}

Compilation message

Village.cpp: In lambda function:
Village.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int i = 1; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int i = 2; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp: In instantiation of 'main()::<lambda(auto:23, int, int)> [with auto:23 = main()::<lambda(auto:23, int, int)>]':
Village.cpp:45:23:   required from here
Village.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int i = 1; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int i = 2; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 0 ms 212 KB Partially correct
4 Partially correct 0 ms 212 KB Partially correct
5 Partially correct 0 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Partially correct 0 ms 212 KB Partially correct
8 Partially correct 0 ms 212 KB Partially correct
9 Partially correct 0 ms 212 KB Partially correct
10 Partially correct 1 ms 212 KB Partially correct
11 Partially correct 1 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Partially correct 1 ms 212 KB Partially correct
14 Partially correct 1 ms 212 KB Partially correct
15 Partially correct 1 ms 212 KB Partially correct
16 Partially correct 1 ms 212 KB Partially correct
17 Partially correct 1 ms 316 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 1 ms 320 KB Partially correct
3 Partially correct 1 ms 340 KB Partially correct
4 Partially correct 1 ms 340 KB Partially correct
5 Partially correct 1 ms 340 KB Partially correct
6 Partially correct 1 ms 340 KB Partially correct
7 Partially correct 1 ms 448 KB Partially correct
8 Partially correct 1 ms 324 KB Partially correct
9 Partially correct 1 ms 340 KB Partially correct
10 Partially correct 1 ms 340 KB Partially correct
11 Partially correct 1 ms 340 KB Partially correct
12 Partially correct 1 ms 340 KB Partially correct
13 Partially correct 1 ms 340 KB Partially correct
14 Partially correct 1 ms 328 KB Partially correct
15 Partially correct 1 ms 328 KB Partially correct
16 Partially correct 1 ms 340 KB Partially correct
17 Partially correct 1 ms 324 KB Partially correct
18 Partially correct 1 ms 328 KB Partially correct
19 Partially correct 1 ms 324 KB Partially correct
20 Partially correct 1 ms 340 KB Partially correct
21 Partially correct 1 ms 320 KB Partially correct
22 Partially correct 1 ms 340 KB Partially correct
23 Partially correct 1 ms 328 KB Partially correct
24 Partially correct 1 ms 340 KB Partially correct
25 Partially correct 1 ms 340 KB Partially correct
26 Partially correct 1 ms 340 KB Partially correct
27 Partially correct 1 ms 340 KB Partially correct
28 Partially correct 1 ms 340 KB Partially correct
29 Partially correct 1 ms 384 KB Partially correct
30 Partially correct 1 ms 340 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 0 ms 212 KB Partially correct
4 Partially correct 0 ms 212 KB Partially correct
5 Partially correct 0 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Partially correct 0 ms 212 KB Partially correct
8 Partially correct 0 ms 212 KB Partially correct
9 Partially correct 0 ms 212 KB Partially correct
10 Partially correct 1 ms 212 KB Partially correct
11 Partially correct 1 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Partially correct 1 ms 212 KB Partially correct
14 Partially correct 1 ms 212 KB Partially correct
15 Partially correct 1 ms 212 KB Partially correct
16 Partially correct 1 ms 212 KB Partially correct
17 Partially correct 1 ms 316 KB Partially correct
18 Partially correct 1 ms 212 KB Partially correct
19 Partially correct 1 ms 320 KB Partially correct
20 Partially correct 1 ms 340 KB Partially correct
21 Partially correct 1 ms 340 KB Partially correct
22 Partially correct 1 ms 340 KB Partially correct
23 Partially correct 1 ms 340 KB Partially correct
24 Partially correct 1 ms 448 KB Partially correct
25 Partially correct 1 ms 324 KB Partially correct
26 Partially correct 1 ms 340 KB Partially correct
27 Partially correct 1 ms 340 KB Partially correct
28 Partially correct 1 ms 340 KB Partially correct
29 Partially correct 1 ms 340 KB Partially correct
30 Partially correct 1 ms 340 KB Partially correct
31 Partially correct 1 ms 328 KB Partially correct
32 Partially correct 1 ms 328 KB Partially correct
33 Partially correct 1 ms 340 KB Partially correct
34 Partially correct 1 ms 324 KB Partially correct
35 Partially correct 1 ms 328 KB Partially correct
36 Partially correct 1 ms 324 KB Partially correct
37 Partially correct 1 ms 340 KB Partially correct
38 Partially correct 1 ms 320 KB Partially correct
39 Partially correct 1 ms 340 KB Partially correct
40 Partially correct 1 ms 328 KB Partially correct
41 Partially correct 1 ms 340 KB Partially correct
42 Partially correct 1 ms 340 KB Partially correct
43 Partially correct 1 ms 340 KB Partially correct
44 Partially correct 1 ms 340 KB Partially correct
45 Partially correct 1 ms 340 KB Partially correct
46 Partially correct 1 ms 384 KB Partially correct
47 Partially correct 1 ms 340 KB Partially correct
48 Partially correct 51 ms 7440 KB Partially correct
49 Partially correct 102 ms 8196 KB Partially correct
50 Partially correct 72 ms 8264 KB Partially correct
51 Partially correct 45 ms 6476 KB Partially correct
52 Partially correct 70 ms 8104 KB Partially correct
53 Partially correct 83 ms 7272 KB Partially correct
54 Partially correct 34 ms 11212 KB Partially correct
55 Partially correct 78 ms 23156 KB Partially correct
56 Partially correct 75 ms 15548 KB Partially correct
57 Partially correct 65 ms 13004 KB Partially correct
58 Partially correct 59 ms 10728 KB Partially correct
59 Partially correct 61 ms 8440 KB Partially correct
60 Partially correct 41 ms 8496 KB Partially correct
61 Partially correct 68 ms 8708 KB Partially correct
62 Partially correct 54 ms 8572 KB Partially correct
63 Partially correct 58 ms 8056 KB Partially correct
64 Partially correct 65 ms 8492 KB Partially correct
65 Partially correct 53 ms 8708 KB Partially correct
66 Partially correct 47 ms 8200 KB Partially correct
67 Partially correct 30 ms 6524 KB Partially correct
68 Partially correct 44 ms 7384 KB Partially correct
69 Partially correct 50 ms 8688 KB Partially correct
70 Partially correct 49 ms 8136 KB Partially correct
71 Partially correct 40 ms 6092 KB Partially correct
72 Partially correct 47 ms 6932 KB Partially correct
73 Partially correct 55 ms 8688 KB Partially correct
74 Partially correct 47 ms 7872 KB Partially correct
75 Partially correct 72 ms 8012 KB Partially correct
76 Partially correct 66 ms 8100 KB Partially correct
77 Partially correct 60 ms 8260 KB Partially correct
78 Partially correct 33 ms 5656 KB Partially correct
79 Partially correct 44 ms 6460 KB Partially correct
80 Partially correct 55 ms 8092 KB Partially correct
81 Partially correct 48 ms 8268 KB Partially correct
82 Partially correct 53 ms 8432 KB Partially correct