답안 #575598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575598 2022-06-11T06:32:54 Z talant117408 Village (BOI20_village) C++17
50 / 100
118 ms 20676 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'

void solve() {
    int n;
    cin >> n;
    vector <int> graph[n];
    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    
    int cost[2];
    cost[0] = cost[1] = 0;
    vector <vector <int>> rear(2, vector <int> (n, -1));
    
    function <int(int, int)> find_smallest = [&](int v, int p) {
        vector <int> children;
        for (auto to : graph[v]) {
            if (to == p) continue;
            if (find_smallest(to, v)) {
                children.pb(to);
            }
        }
        if (sz(children) == 0) {
            if (v) return 1;
            cost[0] += 2;
            int x = graph[v][0];
            rear[0][v] = rear[0][x];
            rear[0][x] = v;
        }
        else if (sz(children)&1) {
            cost[0] += int(sz(children)/2)*4+2;
            rear[0][v] = children[0];
            rear[0][children[0]] = v;
            for (int i = 1; i < sz(children); i += 2) {
                rear[0][children[i]] = children[i+1];
                rear[0][children[i+1]] = children[i];
            }
        }
        else {
            cost[0] += sz(children)*2;
            rear[0][v] = children[1];
            rear[0][children[1]] = children[0];
            rear[0][children[0]] = v;
            for (int i = 2; i < sz(children); i += 2) {
                rear[0][children[i]] = children[i+1];
                rear[0][children[i+1]] = children[i];
            }
        }
        return 0;
    };
    find_smallest(0, 0);
    
    cout << cost[0] << ' ' << cost[1] << endl;
    for (int i = 0; i < 2; i++) {
        for (auto to : rear[i]) cout << (to == -1 ? to+2 : to+1) << ' ';
        cout << endl;
    }
}

int main() {
    //~ do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 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 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 1 ms 212 KB Partially correct
9 Partially correct 0 ms 300 KB Partially correct
10 Partially correct 1 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 304 KB Partially correct
13 Partially correct 1 ms 212 KB Partially correct
14 Partially correct 0 ms 212 KB Partially correct
15 Partially correct 0 ms 300 KB Partially correct
16 Partially correct 1 ms 212 KB Partially correct
17 Partially correct 0 ms 212 KB Partially correct
# 결과 실행 시간 메모리 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 212 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 432 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 2 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 352 KB Partially correct
18 Partially correct 1 ms 340 KB Partially correct
19 Partially correct 1 ms 308 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 304 KB Partially correct
27 Partially correct 1 ms 212 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
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 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 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 1 ms 212 KB Partially correct
9 Partially correct 0 ms 300 KB Partially correct
10 Partially correct 1 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 304 KB Partially correct
13 Partially correct 1 ms 212 KB Partially correct
14 Partially correct 0 ms 212 KB Partially correct
15 Partially correct 0 ms 300 KB Partially correct
16 Partially correct 1 ms 212 KB Partially correct
17 Partially correct 0 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 212 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 432 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 2 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 352 KB Partially correct
35 Partially correct 1 ms 340 KB Partially correct
36 Partially correct 1 ms 308 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 304 KB Partially correct
44 Partially correct 1 ms 212 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 83 ms 7784 KB Partially correct
49 Partially correct 107 ms 8752 KB Partially correct
50 Partially correct 91 ms 8588 KB Partially correct
51 Partially correct 69 ms 6684 KB Partially correct
52 Partially correct 99 ms 8468 KB Partially correct
53 Partially correct 89 ms 7676 KB Partially correct
54 Partially correct 45 ms 9988 KB Partially correct
55 Partially correct 118 ms 20676 KB Partially correct
56 Partially correct 108 ms 14452 KB Partially correct
57 Partially correct 99 ms 12468 KB Partially correct
58 Partially correct 95 ms 10608 KB Partially correct
59 Partially correct 93 ms 8756 KB Partially correct
60 Partially correct 78 ms 9232 KB Partially correct
61 Partially correct 82 ms 9292 KB Partially correct
62 Partially correct 83 ms 9000 KB Partially correct
63 Partially correct 79 ms 8384 KB Partially correct
64 Partially correct 84 ms 8888 KB Partially correct
65 Partially correct 83 ms 8988 KB Partially correct
66 Partially correct 74 ms 8508 KB Partially correct
67 Partially correct 57 ms 6880 KB Partially correct
68 Partially correct 70 ms 7664 KB Partially correct
69 Partially correct 86 ms 9032 KB Partially correct
70 Partially correct 76 ms 8420 KB Partially correct
71 Partially correct 54 ms 6328 KB Partially correct
72 Partially correct 65 ms 7152 KB Partially correct
73 Partially correct 84 ms 9084 KB Partially correct
74 Partially correct 71 ms 8208 KB Partially correct
75 Partially correct 99 ms 8488 KB Partially correct
76 Partially correct 88 ms 8392 KB Partially correct
77 Partially correct 86 ms 8604 KB Partially correct
78 Partially correct 60 ms 5920 KB Partially correct
79 Partially correct 71 ms 6836 KB Partially correct
80 Partially correct 92 ms 8388 KB Partially correct
81 Partially correct 87 ms 8716 KB Partially correct
82 Partially correct 79 ms 8804 KB Partially correct