답안 #971995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971995 2024-04-29T16:32:02 Z jadai007 Village (BOI20_village) C++17
75 / 100
61 ms 17868 KB
#include<bits/stdc++.h>

using namespace std;

int n, dp[100100], vln[100100], vlx[100100], ansn, ansx, cen, depth[100100];
vector<int> vc[100100], ans;

void dfs(int u, int pa){
    for(auto v:vc[u]){
        if(v == pa) continue;
        dfs(v, u);
        if(vln[v] == v){
            ansn+=2;
            swap(vln[v], vln[u]);
        }
        dp[u]+=dp[v];
    }
}

void dfs2(int u, int pa){
    ans.emplace_back(u);
    for(auto v:vc[u]){
        if(v == pa) continue;
        depth[v] = depth[u] + 1;
        dfs2(v, u);
    }
}

int centroid(int u, int pa){
    for(auto v:vc[u]){
        if(v == pa) continue;
        if(dp[v] > n / 2) return centroid(v, u);
    }
    return u;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i<=n; ++i){
        vln[i] = i;
        dp[i] = 1;
    }
    for(int i = 1; i<n; ++i){
        int a, b; cin >> a >> b;
        vc[a].push_back(b);
        vc[b].push_back(a);
    }
    dfs(1, -1);
    if(vln[1] == 1){
        ansn+=2;
        swap(vln[1], vln[vc[1][0]]);
    }
    cen = centroid(1, -1);
    dfs2(cen, -1);
    for(int i = 1; i<=n; ++i) ansx+=depth[i]*2;
    cout << ansn << ' ' << ansx << '\n';
    for(int i = 0; i<n; ++i) vlx[ans[(i+n/2)%n]] = ans[i];
    for(int i = 1; i<=n; ++i) cout << vln[i] << ' ';
    cout << '\n';
    for(int i = 1; i<=n; ++i) cout << vlx[i] << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 3160 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 1 ms 2664 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2904 KB Output is correct
24 Correct 1 ms 2904 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 1 ms 2904 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 3160 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2908 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 1 ms 2664 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2908 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 38 ms 9676 KB Output is correct
49 Correct 40 ms 10332 KB Output is correct
50 Correct 44 ms 10452 KB Output is correct
51 Correct 31 ms 8776 KB Output is correct
52 Correct 39 ms 10196 KB Output is correct
53 Correct 35 ms 9580 KB Output is correct
54 Correct 23 ms 9940 KB Output is correct
55 Partially correct 54 ms 17868 KB Partially correct
56 Partially correct 58 ms 14024 KB Partially correct
57 Correct 49 ms 12672 KB Output is correct
58 Correct 42 ms 11472 KB Output is correct
59 Correct 45 ms 10440 KB Output is correct
60 Correct 36 ms 10636 KB Output is correct
61 Correct 47 ms 10680 KB Output is correct
62 Correct 39 ms 10708 KB Output is correct
63 Correct 34 ms 10208 KB Output is correct
64 Correct 46 ms 10704 KB Output is correct
65 Correct 38 ms 10704 KB Output is correct
66 Correct 31 ms 10356 KB Output is correct
67 Correct 26 ms 8692 KB Output is correct
68 Correct 43 ms 9924 KB Output is correct
69 Correct 36 ms 10696 KB Output is correct
70 Correct 32 ms 10444 KB Output is correct
71 Correct 26 ms 8516 KB Output is correct
72 Correct 35 ms 9164 KB Output is correct
73 Correct 35 ms 10696 KB Output is correct
74 Correct 34 ms 10188 KB Output is correct
75 Correct 40 ms 10164 KB Output is correct
76 Correct 47 ms 10184 KB Output is correct
77 Correct 34 ms 10444 KB Output is correct
78 Correct 24 ms 7840 KB Output is correct
79 Correct 30 ms 8648 KB Output is correct
80 Correct 61 ms 10148 KB Output is correct
81 Correct 45 ms 10528 KB Output is correct
82 Correct 34 ms 10708 KB Output is correct