답안 #915192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915192 2024-01-23T13:08:44 Z 3as8 Village (BOI20_village) C++14
50 / 100
88 ms 16744 KB
#include <bits/stdc++.h>

#define ll long long
#define endl "\n"
#define fastIO cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);

#define mid ((l + r) / 2)
#define lChild ((index * 2) + 1)
#define rChild ((index * 2) + 2)

using namespace std;

ll ans = 0;
bool dfs(vector<vector<ll> >& graph, vector<ll>& cur, ll startIndex, ll p) {

    bool hasLeaf = false;
    bool isLeaf = true;
    for(auto el : graph[startIndex]) {
        if(el == p) continue;

        hasLeaf &= dfs(graph, cur, el, startIndex);

        isLeaf = false;

    }

    if(isLeaf && cur[startIndex] == startIndex ) {

        ans += 2;
        //cout<<"swap "<<cur[p] + 1<<" "<<cur[startIndex] + 1<<endl;

        swap(cur[p], cur[startIndex]);

        return isLeaf;
    }

    if(cur[startIndex] == startIndex && p != startIndex) {


        ans += 2;
       // cout<<"swap no leaf "<<cur[p] + 1<<" "<<cur[startIndex] + 1<<endl;

        swap(cur[p], cur[startIndex]);
    }

    return isLeaf;
}


void solve(ll _) {

    ll n; cin>>n;

    vector<vector<ll> > graph(n);
    for(int i = 0; i < n - 1; i++) {
        ll x, y; cin>>x>>y;
        x--; y--;

        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    vector<bool> stat(n, true);
    vector<ll> curr(n);
    for(int i = 0; i < n; i++) curr[i] = i;

    dfs(graph, curr, 0, 0);

    for(int i = 0; i < n; i++) {

        if(curr[i] == i) {
            ans += 2;
            swap(curr[i], curr[graph[i][0]]);

        }

    }

    cout<<ans<<" "<<2<<endl;
    for(auto el : curr) cout<<el + 1<<" ";
    cout<<endl;

    for(auto el : curr) cout<<el + 1<<" ";
    cout<<endl;
}

int main() {


    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);

    ll t = 0; solve(t);
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Partially correct 0 ms 348 KB Partially correct
3 Correct 0 ms 348 KB Output is correct
4 Partially correct 0 ms 348 KB Partially correct
5 Partially correct 1 ms 348 KB Partially correct
6 Partially correct 1 ms 344 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Partially correct 0 ms 348 KB Partially correct
9 Partially correct 1 ms 348 KB Partially correct
10 Partially correct 0 ms 348 KB Partially correct
11 Partially correct 1 ms 348 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 348 KB Partially correct
14 Partially correct 1 ms 348 KB Partially correct
15 Partially correct 0 ms 348 KB Partially correct
16 Partially correct 1 ms 436 KB Partially correct
17 Partially correct 0 ms 348 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Partially correct 1 ms 604 KB Partially correct
3 Partially correct 1 ms 348 KB Partially correct
4 Partially correct 2 ms 348 KB Partially correct
5 Partially correct 1 ms 344 KB Partially correct
6 Partially correct 1 ms 348 KB Partially correct
7 Partially correct 1 ms 348 KB Partially correct
8 Partially correct 2 ms 348 KB Partially correct
9 Partially correct 1 ms 348 KB Partially correct
10 Partially correct 1 ms 600 KB Partially correct
11 Partially correct 1 ms 348 KB Partially correct
12 Partially correct 1 ms 344 KB Partially correct
13 Partially correct 1 ms 348 KB Partially correct
14 Partially correct 1 ms 348 KB Partially correct
15 Partially correct 1 ms 344 KB Partially correct
16 Partially correct 1 ms 348 KB Partially correct
17 Partially correct 1 ms 348 KB Partially correct
18 Partially correct 1 ms 348 KB Partially correct
19 Partially correct 1 ms 348 KB Partially correct
20 Partially correct 1 ms 344 KB Partially correct
21 Partially correct 1 ms 348 KB Partially correct
22 Partially correct 1 ms 348 KB Partially correct
23 Partially correct 1 ms 348 KB Partially correct
24 Partially correct 1 ms 536 KB Partially correct
25 Partially correct 1 ms 348 KB Partially correct
26 Partially correct 1 ms 348 KB Partially correct
27 Partially correct 1 ms 348 KB Partially correct
28 Partially correct 1 ms 348 KB Partially correct
29 Partially correct 1 ms 344 KB Partially correct
30 Partially correct 1 ms 348 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Partially correct 0 ms 348 KB Partially correct
3 Correct 0 ms 348 KB Output is correct
4 Partially correct 0 ms 348 KB Partially correct
5 Partially correct 1 ms 348 KB Partially correct
6 Partially correct 1 ms 344 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Partially correct 0 ms 348 KB Partially correct
9 Partially correct 1 ms 348 KB Partially correct
10 Partially correct 0 ms 348 KB Partially correct
11 Partially correct 1 ms 348 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 348 KB Partially correct
14 Partially correct 1 ms 348 KB Partially correct
15 Partially correct 0 ms 348 KB Partially correct
16 Partially correct 1 ms 436 KB Partially correct
17 Partially correct 0 ms 348 KB Partially correct
18 Partially correct 1 ms 344 KB Partially correct
19 Partially correct 1 ms 604 KB Partially correct
20 Partially correct 1 ms 348 KB Partially correct
21 Partially correct 2 ms 348 KB Partially correct
22 Partially correct 1 ms 344 KB Partially correct
23 Partially correct 1 ms 348 KB Partially correct
24 Partially correct 1 ms 348 KB Partially correct
25 Partially correct 2 ms 348 KB Partially correct
26 Partially correct 1 ms 348 KB Partially correct
27 Partially correct 1 ms 600 KB Partially correct
28 Partially correct 1 ms 348 KB Partially correct
29 Partially correct 1 ms 344 KB Partially correct
30 Partially correct 1 ms 348 KB Partially correct
31 Partially correct 1 ms 348 KB Partially correct
32 Partially correct 1 ms 344 KB Partially correct
33 Partially correct 1 ms 348 KB Partially correct
34 Partially correct 1 ms 348 KB Partially correct
35 Partially correct 1 ms 348 KB Partially correct
36 Partially correct 1 ms 348 KB Partially correct
37 Partially correct 1 ms 344 KB Partially correct
38 Partially correct 1 ms 348 KB Partially correct
39 Partially correct 1 ms 348 KB Partially correct
40 Partially correct 1 ms 348 KB Partially correct
41 Partially correct 1 ms 536 KB Partially correct
42 Partially correct 1 ms 348 KB Partially correct
43 Partially correct 1 ms 348 KB Partially correct
44 Partially correct 1 ms 348 KB Partially correct
45 Partially correct 1 ms 348 KB Partially correct
46 Partially correct 1 ms 344 KB Partially correct
47 Partially correct 1 ms 348 KB Partially correct
48 Partially correct 62 ms 8792 KB Partially correct
49 Partially correct 85 ms 9704 KB Partially correct
50 Partially correct 66 ms 9552 KB Partially correct
51 Partially correct 51 ms 7504 KB Partially correct
52 Partially correct 77 ms 9684 KB Partially correct
53 Partially correct 59 ms 8480 KB Partially correct
54 Partially correct 36 ms 8020 KB Partially correct
55 Partially correct 88 ms 16744 KB Partially correct
56 Partially correct 81 ms 13140 KB Partially correct
57 Partially correct 72 ms 11824 KB Partially correct
58 Partially correct 67 ms 10788 KB Partially correct
59 Partially correct 71 ms 9808 KB Partially correct
60 Partially correct 67 ms 9612 KB Partially correct
61 Partially correct 60 ms 9796 KB Partially correct
62 Partially correct 69 ms 9812 KB Partially correct
63 Partially correct 58 ms 9300 KB Partially correct
64 Partially correct 63 ms 10024 KB Partially correct
65 Partially correct 64 ms 10144 KB Partially correct
66 Partially correct 72 ms 9528 KB Partially correct
67 Partially correct 49 ms 7376 KB Partially correct
68 Partially correct 52 ms 8528 KB Partially correct
69 Partially correct 62 ms 10068 KB Partially correct
70 Partially correct 57 ms 9556 KB Partially correct
71 Partially correct 43 ms 7056 KB Partially correct
72 Partially correct 48 ms 8016 KB Partially correct
73 Partially correct 66 ms 10196 KB Partially correct
74 Partially correct 66 ms 9120 KB Partially correct
75 Partially correct 67 ms 10068 KB Partially correct
76 Partially correct 73 ms 9676 KB Partially correct
77 Partially correct 77 ms 9896 KB Partially correct
78 Partially correct 44 ms 6736 KB Partially correct
79 Partially correct 51 ms 7504 KB Partially correct
80 Partially correct 68 ms 10064 KB Partially correct
81 Partially correct 61 ms 9916 KB Partially correct
82 Partially correct 75 ms 9792 KB Partially correct