Submission #723541

# Submission time Handle Problem Language Result Execution time Memory
723541 2023-04-14T04:47:51 Z t6twotwo Village (BOI20_village) C++17
50 / 100
115 ms 23760 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> amin(n), amax(n);
    iota(amin.begin(), amin.end(), 0);
    iota(amax.begin(), amax.end(), 0);
    int ansmin = 0;
    int64_t ansmax = 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;
        }
        ansmin += b.size() * 2;
        if (b.size() % 2 == 1) {
            swap(amin[x], amin[b[0]]);
            for (int i = 1; i < b.size(); i += 2) {
                swap(amin[b[i]], amin[b[i + 1]]);
            }
        } else {
            swap(amin[x], amin[b[0]]);
            swap(amin[x], amin[b[1]]);
            for (int i = 2; i < b.size(); i += 2) {
                swap(amin[b[i]], amin[b[i + 1]]);
            }
        }
        return 0;
    };
    if (dfs(dfs, 0, -1)) {
        swap(amin[0], amin[adj[0][0]]);
        ansmin += 2;
    }
    vector<int> sz(n);
    auto init = [&](auto init, int x, int p) -> void {
        sz[x] = 1;
        for (int y : adj[x]) {
            if (y != p) {
                init(init, y, x);
                sz[x] += sz[y];
            }
        }
        ansmax += 2 * min(sz[x], n - sz[x]);
    };
    auto find = [&](auto find, int x, int p, int s) -> int {
        for (int y : adj[x]) {
            if (y != p && sz[y] * 2 > s) {
                return find(find, y, x, s);
            }
        }
        return x;
    };
    init(init, 0, -1);
    int c = find(find, 0, -1, n);
    vector<int> b;
    auto dfs2 = [&](auto dfs2, int x, int p) -> void {
        b.push_back(x);
        for (int y : adj[x]) {
            if (y != p) {
                dfs2(dfs2, y, x);
            }
        }
    };
    dfs2(dfs2, 0, -1);
    for (int i = 0; i < n; i++) {
        swap(amax[b[i]], amax[b[(i + n / 2) % n]]);
    }
    cout << ansmin << " " << ansmax << "\n";
    for (int i = 0; i < n; i++) {
        cout << amin[i] + 1 << " \n"[i == n - 1];
    }
    for (int i = 0; i < n; i++) {
        cout << amax[i] + 1 << " \n"[i == n - 1];
    }
    return 6/22;
}

Compilation message

Village.cpp: In lambda function:
Village.cpp:35:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             for (int i = 1; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp:41:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             for (int i = 2; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp: In function 'int main()':
Village.cpp:71:9: warning: unused variable 'c' [-Wunused-variable]
   71 |     int c = find(find, 0, -1, n);
      |         ^
Village.cpp: In instantiation of 'main()::<lambda(auto:23, int, int)> [with auto:23 = main()::<lambda(auto:23, int, int)>]':
Village.cpp:47:23:   required from here
Village.cpp:35:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             for (int i = 1; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp:41:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             for (int i = 2; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 0 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 1 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Correct 0 ms 212 KB Output is correct
8 Partially correct 0 ms 212 KB Partially correct
9 Partially correct 0 ms 212 KB Partially correct
10 Partially correct 0 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Partially correct 0 ms 212 KB Partially correct
14 Partially correct 1 ms 212 KB Partially correct
15 Partially correct 0 ms 212 KB Partially correct
16 Partially correct 0 ms 212 KB Partially correct
17 Partially correct 1 ms 212 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 1 ms 340 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 496 KB Partially correct
8 Partially correct 1 ms 340 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 340 KB Partially correct
15 Partially correct 1 ms 340 KB Partially correct
16 Partially correct 1 ms 340 KB Partially correct
17 Partially correct 1 ms 340 KB Partially correct
18 Partially correct 1 ms 340 KB Partially correct
19 Partially correct 1 ms 340 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 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 340 KB Partially correct
30 Partially correct 1 ms 340 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 0 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 1 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Correct 0 ms 212 KB Output is correct
8 Partially correct 0 ms 212 KB Partially correct
9 Partially correct 0 ms 212 KB Partially correct
10 Partially correct 0 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Partially correct 0 ms 212 KB Partially correct
14 Partially correct 1 ms 212 KB Partially correct
15 Partially correct 0 ms 212 KB Partially correct
16 Partially correct 0 ms 212 KB Partially correct
17 Partially correct 1 ms 212 KB Partially correct
18 Partially correct 1 ms 212 KB Partially correct
19 Partially correct 1 ms 340 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 496 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 340 KB Partially correct
30 Partially correct 1 ms 340 KB Partially correct
31 Partially correct 1 ms 340 KB Partially correct
32 Partially correct 1 ms 340 KB Partially correct
33 Partially correct 1 ms 340 KB Partially correct
34 Partially correct 1 ms 340 KB Partially correct
35 Partially correct 1 ms 340 KB Partially correct
36 Partially correct 1 ms 340 KB Partially correct
37 Partially correct 1 ms 340 KB Partially correct
38 Partially correct 1 ms 340 KB Partially correct
39 Partially correct 1 ms 340 KB Partially correct
40 Partially correct 1 ms 340 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 340 KB Partially correct
47 Partially correct 1 ms 340 KB Partially correct
48 Partially correct 73 ms 7952 KB Partially correct
49 Partially correct 97 ms 8776 KB Partially correct
50 Partially correct 71 ms 8776 KB Partially correct
51 Partially correct 54 ms 6884 KB Partially correct
52 Partially correct 115 ms 8720 KB Partially correct
53 Partially correct 53 ms 7896 KB Partially correct
54 Partially correct 35 ms 11468 KB Partially correct
55 Partially correct 95 ms 23760 KB Partially correct
56 Partially correct 92 ms 15808 KB Partially correct
57 Partially correct 96 ms 13424 KB Partially correct
58 Partially correct 96 ms 11212 KB Partially correct
59 Partially correct 70 ms 8912 KB Partially correct
60 Partially correct 53 ms 9448 KB Partially correct
61 Partially correct 53 ms 9028 KB Partially correct
62 Partially correct 61 ms 9116 KB Partially correct
63 Partially correct 55 ms 8620 KB Partially correct
64 Partially correct 62 ms 9168 KB Partially correct
65 Partially correct 69 ms 9168 KB Partially correct
66 Partially correct 49 ms 8676 KB Partially correct
67 Partially correct 34 ms 6828 KB Partially correct
68 Partially correct 60 ms 7876 KB Partially correct
69 Partially correct 53 ms 9256 KB Partially correct
70 Partially correct 52 ms 8640 KB Partially correct
71 Partially correct 36 ms 6468 KB Partially correct
72 Partially correct 41 ms 7332 KB Partially correct
73 Partially correct 70 ms 9284 KB Partially correct
74 Partially correct 49 ms 8412 KB Partially correct
75 Partially correct 90 ms 8612 KB Partially correct
76 Partially correct 70 ms 8596 KB Partially correct
77 Partially correct 55 ms 8724 KB Partially correct
78 Partially correct 41 ms 6088 KB Partially correct
79 Partially correct 41 ms 6980 KB Partially correct
80 Partially correct 84 ms 8664 KB Partially correct
81 Partially correct 57 ms 8920 KB Partially correct
82 Partially correct 55 ms 9024 KB Partially correct