Submission #1000167

# Submission time Handle Problem Language Result Execution time Memory
1000167 2024-06-16T19:25:08 Z y_combinator Village (BOI20_village) C++17
100 / 100
43 ms 16720 KB
#include <algorithm>
#include <ios>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>

template <typename F>
class YCombinator {

private:

    const F f = nullptr;

public:

    explicit YCombinator(F&& f) : f(f) {}

    template <typename... Ts>
    decltype(auto) operator()(Ts&&... arguments) const {

        return f(*this, std::forward<Ts>(arguments)...);

    }

};

template <typename F>
YCombinator(F) -> YCombinator<F>;

auto solve() {

    auto n = 0;

    std::cin >> n;

    auto adj = std::vector<std::vector<int>>(n);

    for (auto i = 0; i < n - 1; ++i) {
        auto a = 0;
        auto b = 0;
        std::cin >> a >> b;
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    auto idxs = std::vector<int>(n);
    auto mn_len = 0;
    auto mx_len = 0ll;
    auto order = std::vector<int>();
    auto szs = std::vector<int>(n, 1);
    auto v = std::vector<int>(n);

    order.reserve(n);

    std::iota(std::begin(v), std::end(v), 0);

    YCombinator(
        [&](auto self, int node, int par) -> void {
            order.push_back(node);
            for (auto x : adj[node]) {
                if (x != par) {
                    self(x, node);
                    mx_len += std::min(szs[x], n - szs[x]) * 2;
                    szs[node] += szs[x];
                }
            }
            if (v[node] == node) {
                std::swap(v[node], v[par != -1 ? par : adj[node][0]]);
                mn_len += 2;
            }
        }
    )(0, -1);

    std::cout << mn_len << ' ' << mx_len << '\n';

    for (auto i = 0; i < n; ++i) {
        std::cout << v[i] + 1 << (i < n - 1 ? ' ' : '\n');
        idxs[order[i]] = i;
    }

    for (auto i = 0; i < n; ++i) {
        std::cout << order[(idxs[i] + n / 2) % n] + 1 << (i < n - 1 ? ' ' : '\n');
    }

}

auto main() -> int {

    std::cin.tie(nullptr);

    std::ios_base::sync_with_stdio(false);

    solve();

    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 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 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 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 1 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 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 508 KB Output is correct
19 Correct 1 ms 420 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 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 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 508 KB Output is correct
36 Correct 1 ms 420 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 37 ms 9040 KB Output is correct
49 Correct 37 ms 9812 KB Output is correct
50 Correct 39 ms 9764 KB Output is correct
51 Correct 28 ms 7760 KB Output is correct
52 Correct 36 ms 9808 KB Output is correct
53 Correct 33 ms 8784 KB Output is correct
54 Correct 20 ms 8312 KB Output is correct
55 Correct 43 ms 16720 KB Output is correct
56 Correct 41 ms 12888 KB Output is correct
57 Correct 37 ms 11756 KB Output is correct
58 Correct 39 ms 10836 KB Output is correct
59 Correct 35 ms 9860 KB Output is correct
60 Correct 29 ms 9940 KB Output is correct
61 Correct 32 ms 10068 KB Output is correct
62 Correct 33 ms 10328 KB Output is correct
63 Correct 33 ms 9552 KB Output is correct
64 Correct 34 ms 10068 KB Output is correct
65 Correct 32 ms 10320 KB Output is correct
66 Correct 29 ms 9556 KB Output is correct
67 Correct 24 ms 7516 KB Output is correct
68 Correct 28 ms 8784 KB Output is correct
69 Correct 33 ms 10324 KB Output is correct
70 Correct 32 ms 9552 KB Output is correct
71 Correct 23 ms 7248 KB Output is correct
72 Correct 25 ms 8276 KB Output is correct
73 Correct 39 ms 10320 KB Output is correct
74 Correct 31 ms 9556 KB Output is correct
75 Correct 40 ms 9812 KB Output is correct
76 Correct 35 ms 9808 KB Output is correct
77 Correct 33 ms 9824 KB Output is correct
78 Correct 22 ms 6748 KB Output is correct
79 Correct 27 ms 7816 KB Output is correct
80 Correct 36 ms 9816 KB Output is correct
81 Correct 34 ms 9808 KB Output is correct
82 Correct 30 ms 10152 KB Output is correct