Submission #573886

# Submission time Handle Problem Language Result Execution time Memory
573886 2022-06-07T11:26:16 Z tengiz05 Village (BOI20_village) C++17
0 / 100
1 ms 320 KB
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<std::vector<int>> adj(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    int mn = 0;
    
    std::vector<int> w(n, -1);
    
    std::function<void(int, int)> dfs = [&](int u, int p) {
        std::vector<int> a;
        int x = -1;
        for (int v : adj[u]) {
            if (v == p)
                continue;
            dfs(v, u);
            if (w[v] == -1) {
                a.push_back(v);
            }
            x = v;
        }
        int m = a.size();
        if (m % 2 == 1) {
            for (int i = 0; i < m - 2; i += 2) {
                mn += 4;
                w[a[i]] = a[i + 1];
                w[a[i + 1]] = a[i];
            }
            mn += 2;
            w[u] = a[m - 1];
            w[a[m - 1]] = u;
        } else {
            for (int i = 0; i < m; i += 2) {
                mn += 4;
                w[a[i]] = a[i + 1];
                w[a[i + 1]] = a[i];
            }
            if (p == -1) {
                if (m >= 2) {
                    w[u] = a[0];
                    w[a[0]] = a[1];
                    w[a[1]] = u;
                } else {
                    mn += 2;
                    w[u] = w[x];
                    w[x] = u;
                }
            }
        }
    };
    
    dfs(0, -1);
    
    std::cout << mn << " " << 0 << "\n";
    
    for (int i = 0; i < n; i++) {
        std::cout << w[i] + 1 << " \n"[i == n - 1];
    }
    
    for (int i = 0; i < n; i++) {
        std::cout << 1 << " \n"[i == n - 1];
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 320 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 1 ms 212 KB Partially correct
4 Partially correct 1 ms 212 KB Partially correct
5 Partially correct 0 ms 316 KB Partially correct
6 Partially correct 1 ms 320 KB Partially correct
7 Partially correct 1 ms 212 KB Partially correct
8 Partially correct 1 ms 256 KB Partially correct
9 Partially correct 1 ms 212 KB Partially correct
10 Partially correct 0 ms 212 KB Partially correct
11 Partially correct 1 ms 212 KB Partially correct
12 Partially correct 0 ms 212 KB Partially correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 320 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 1 ms 212 KB Partially correct
4 Partially correct 1 ms 212 KB Partially correct
5 Partially correct 0 ms 316 KB Partially correct
6 Partially correct 1 ms 320 KB Partially correct
7 Partially correct 1 ms 212 KB Partially correct
8 Partially correct 1 ms 256 KB Partially correct
9 Partially correct 1 ms 212 KB Partially correct
10 Partially correct 0 ms 212 KB Partially correct
11 Partially correct 1 ms 212 KB Partially correct
12 Partially correct 0 ms 212 KB Partially correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -