Submission #395379

# Submission time Handle Problem Language Result Execution time Memory
395379 2021-04-28T09:53:46 Z KoD Village (BOI20_village) C++17
50 / 100
155 ms 21764 KB
#include <bits/stdc++.h>

template <class T>
using Vec = std::vector<T>;

int main() {
    int N;
    std::cin >> N;
    Vec<Vec<int>> graph(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        std::cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    int min = -1, max = -1;
    Vec<int> min_v(N), max_v(N);
    // minimum
    {
        Vec<std::pair<int, int>> use;
        auto dfs = [&](auto&& dfs, const int u, const int p) -> bool {
            int child = -1;
            bool done = false;
            for (const int v: graph[u]) {
                if (v != p) {
                    if (dfs(dfs, v, u)) {
                        done = true;
                    }
                    child = v;
                }
            }
            if (!done) {
                if (p == -1) {
                    use.emplace_back(u, child);
                    return false;
                }
                use.emplace_back(u, p);
                return true;
            }
            return false;
        };
        dfs(dfs, 0, -1);
        min = 2 * (int) use.size();
        Vec<Vec<int>> tree(N);
        for (const auto [u, v]: use) {
            tree[u].push_back(v);
            tree[v].push_back(u);
        }
        Vec<bool> done(N);
        Vec<int> order;
        auto build = [&](auto&& build, const int u, const int p) -> void {
            done[u] = true;
            order.push_back(u);
            for (const auto v: tree[u]) {
                if (v != p) {
                    build(build, v, u);
                }
            }
        };
        for (int r = 0; r < N; ++r) {
            if (!done[r]) {
                build(build, r, -1);
                const auto len = (int) order.size();
                for (int i = 0; i < len; ++i) {
                    min_v[order[i]] = order[(i + 1) % len];
                }
                order.clear();
            }
        }
    }
    // maximum
    {
        max = 0;
        // Vec<int> subtree(N);
        // auto setup = [&](auto&& setup, const int u, const int p) -> void {
        //     subtree[u] = 1;
        //     for (const auto v: graph[u]) {
        //         if (v != p) {
        //             setup(setup, v, u);
        //             subtree[u] += subtree[v];
        //         }
        //     }
        //     if (p != -1) {
        //         max += 2 * std::min(subtree[u], N - subtree[u]);
        //     }
        // };
        // setup(setup, 0, -1);
        // auto find = [&](auto&& find, const int u, const int p) -> int {
        //     for (const auto v: graph[u]) {
        //         if (v != p and subtree[v] * 2 > N) {
        //             return find(find, v, u);
        //         }
        //     }
        //     return u;
        // };
        // const auto cent = find(find, 0, -1);
        // Vec<Vec<int>> group;
        // auto listup = [&](auto&& listup, const int u, const int p) -> void {
        //     group.back().push_back(u);
        //     for (const auto v: graph[u]) {
        //         if (v != p) {
        //             listup(listup, v, u);
        //         }
        //     }
        // };
        // for (const auto u: graph[cent]) {
        //     group.push_back({});
        //     listup(listup, u, cent);
        // }
        // if (N % 2 == 0) {
        //     group.push_back({});
        //     group.back().push_back(cent);
        //     Vec<int> up, down;
        //     for (const auto& g: group) {
        //         for (const auto u: g) {
        //             ((int) up.size() < N / 2 ? up : down).push_back(u);
        //         }
        //     }
        //     for (int i = 0; i < N / 2; ++i) {
        //         max_v[up[i]] = down[i];
        //         max_v[down[i]] = up[i];
        //     }
        // }
        // else {
        //     Vec<int> up, down;
        //     for (const auto& g: group) {
        //         for (const auto u: g) {
        //             ((int) up.size() < (N - 1) / 2 ? up : down).push_back(u);
        //         }
        //     }
        //     for (int i = 0; i < (N - 1) / 2; ++i) {
        //         max_v[up[i]] = down[i];
        //         max_v[down[i]] = up[i];
        //     }            
        //     max_v[up[0]] = cent;
        //     max_v[cent] = down[0];
        // }
    }
    std::cout << min << ' ' << max << '\n';
    for (int i = 0; i < N; ++i) {
        std::cout << min_v[i] + 1 << " \n"[i + 1 == N];
    }
    for (int i = 0; i < N; ++i) {
        std::cout << max_v[i] + 1 << " \n"[i + 1 == N];
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Partially correct
2 Partially correct 1 ms 204 KB Partially correct
3 Partially correct 1 ms 204 KB Partially correct
4 Partially correct 1 ms 204 KB Partially correct
5 Partially correct 1 ms 296 KB Partially correct
6 Partially correct 1 ms 204 KB Partially correct
7 Partially correct 1 ms 204 KB Partially correct
8 Partially correct 1 ms 204 KB Partially correct
9 Partially correct 1 ms 204 KB Partially correct
10 Partially correct 1 ms 204 KB Partially correct
11 Partially correct 1 ms 204 KB Partially correct
12 Partially correct 1 ms 296 KB Partially correct
13 Partially correct 1 ms 204 KB Partially correct
14 Partially correct 1 ms 204 KB Partially correct
15 Partially correct 1 ms 204 KB Partially correct
16 Partially correct 1 ms 204 KB Partially correct
17 Partially correct 1 ms 296 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct
2 Partially correct 1 ms 296 KB Partially correct
3 Partially correct 2 ms 332 KB Partially correct
4 Partially correct 2 ms 332 KB Partially correct
5 Partially correct 2 ms 332 KB Partially correct
6 Partially correct 2 ms 332 KB Partially correct
7 Partially correct 2 ms 460 KB Partially correct
8 Partially correct 2 ms 332 KB Partially correct
9 Partially correct 2 ms 332 KB Partially correct
10 Partially correct 2 ms 332 KB Partially correct
11 Partially correct 2 ms 332 KB Partially correct
12 Partially correct 2 ms 332 KB Partially correct
13 Partially correct 2 ms 424 KB Partially correct
14 Partially correct 2 ms 332 KB Partially correct
15 Partially correct 2 ms 332 KB Partially correct
16 Partially correct 2 ms 332 KB Partially correct
17 Partially correct 3 ms 352 KB Partially correct
18 Partially correct 2 ms 332 KB Partially correct
19 Partially correct 2 ms 332 KB Partially correct
20 Partially correct 2 ms 428 KB Partially correct
21 Partially correct 2 ms 336 KB Partially correct
22 Partially correct 2 ms 332 KB Partially correct
23 Partially correct 2 ms 332 KB Partially correct
24 Partially correct 2 ms 332 KB Partially correct
25 Partially correct 1 ms 332 KB Partially correct
26 Partially correct 2 ms 332 KB Partially correct
27 Partially correct 1 ms 332 KB Partially correct
28 Partially correct 2 ms 332 KB Partially correct
29 Partially correct 2 ms 332 KB Partially correct
30 Partially correct 2 ms 332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Partially correct
2 Partially correct 1 ms 204 KB Partially correct
3 Partially correct 1 ms 204 KB Partially correct
4 Partially correct 1 ms 204 KB Partially correct
5 Partially correct 1 ms 296 KB Partially correct
6 Partially correct 1 ms 204 KB Partially correct
7 Partially correct 1 ms 204 KB Partially correct
8 Partially correct 1 ms 204 KB Partially correct
9 Partially correct 1 ms 204 KB Partially correct
10 Partially correct 1 ms 204 KB Partially correct
11 Partially correct 1 ms 204 KB Partially correct
12 Partially correct 1 ms 296 KB Partially correct
13 Partially correct 1 ms 204 KB Partially correct
14 Partially correct 1 ms 204 KB Partially correct
15 Partially correct 1 ms 204 KB Partially correct
16 Partially correct 1 ms 204 KB Partially correct
17 Partially correct 1 ms 296 KB Partially correct
18 Partially correct 1 ms 332 KB Partially correct
19 Partially correct 1 ms 296 KB Partially correct
20 Partially correct 2 ms 332 KB Partially correct
21 Partially correct 2 ms 332 KB Partially correct
22 Partially correct 2 ms 332 KB Partially correct
23 Partially correct 2 ms 332 KB Partially correct
24 Partially correct 2 ms 460 KB Partially correct
25 Partially correct 2 ms 332 KB Partially correct
26 Partially correct 2 ms 332 KB Partially correct
27 Partially correct 2 ms 332 KB Partially correct
28 Partially correct 2 ms 332 KB Partially correct
29 Partially correct 2 ms 332 KB Partially correct
30 Partially correct 2 ms 424 KB Partially correct
31 Partially correct 2 ms 332 KB Partially correct
32 Partially correct 2 ms 332 KB Partially correct
33 Partially correct 2 ms 332 KB Partially correct
34 Partially correct 3 ms 352 KB Partially correct
35 Partially correct 2 ms 332 KB Partially correct
36 Partially correct 2 ms 332 KB Partially correct
37 Partially correct 2 ms 428 KB Partially correct
38 Partially correct 2 ms 336 KB Partially correct
39 Partially correct 2 ms 332 KB Partially correct
40 Partially correct 2 ms 332 KB Partially correct
41 Partially correct 2 ms 332 KB Partially correct
42 Partially correct 1 ms 332 KB Partially correct
43 Partially correct 2 ms 332 KB Partially correct
44 Partially correct 1 ms 332 KB Partially correct
45 Partially correct 2 ms 332 KB Partially correct
46 Partially correct 2 ms 332 KB Partially correct
47 Partially correct 2 ms 332 KB Partially correct
48 Partially correct 119 ms 11712 KB Partially correct
49 Partially correct 137 ms 12868 KB Partially correct
50 Partially correct 145 ms 13100 KB Partially correct
51 Partially correct 100 ms 10200 KB Partially correct
52 Partially correct 131 ms 12788 KB Partially correct
53 Partially correct 121 ms 11492 KB Partially correct
54 Partially correct 67 ms 10824 KB Partially correct
55 Partially correct 155 ms 21764 KB Partially correct
56 Partially correct 155 ms 16924 KB Partially correct
57 Partially correct 134 ms 15428 KB Partially correct
58 Partially correct 133 ms 14272 KB Partially correct
59 Partially correct 142 ms 12964 KB Partially correct
60 Partially correct 111 ms 14772 KB Partially correct
61 Partially correct 121 ms 14132 KB Partially correct
62 Partially correct 125 ms 14016 KB Partially correct
63 Partially correct 129 ms 13244 KB Partially correct
64 Partially correct 126 ms 13788 KB Partially correct
65 Partially correct 128 ms 14160 KB Partially correct
66 Partially correct 129 ms 13268 KB Partially correct
67 Partially correct 92 ms 10608 KB Partially correct
68 Partially correct 119 ms 11944 KB Partially correct
69 Partially correct 128 ms 14324 KB Partially correct
70 Partially correct 122 ms 13368 KB Partially correct
71 Partially correct 83 ms 9932 KB Partially correct
72 Partially correct 103 ms 11320 KB Partially correct
73 Partially correct 119 ms 14192 KB Partially correct
74 Partially correct 112 ms 12952 KB Partially correct
75 Partially correct 147 ms 12880 KB Partially correct
76 Partially correct 131 ms 12808 KB Partially correct
77 Partially correct 127 ms 13196 KB Partially correct
78 Partially correct 89 ms 9148 KB Partially correct
79 Partially correct 94 ms 10536 KB Partially correct
80 Partially correct 138 ms 12788 KB Partially correct
81 Partially correct 125 ms 13572 KB Partially correct
82 Partially correct 125 ms 13720 KB Partially correct