답안 #896171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896171 2023-12-31T23:56:56 Z ShaShi Village (BOI20_village) C++17
75 / 100
54 ms 17868 KB
#include <bits/stdc++.h>
// #define int long long 
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << endl, exit(0);
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
 
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
 
const int MAXN = (int)1e5 + 7;
const int MOD = 998244353;
const int INF = (int)1e9 + 7;
 
 
 
int n, m, t, flag, k, u, v, w, ans, ans2, tmp, tmp2, tmp3, tmp4;
int arr[MAXN], arr2[MAXN], par[MAXN], h[MAXN], sz[MAXN], cent;
int arr3[MAXN], arr4[MAXN];
vector<int> adj[MAXN];

bool DFS(int v, int p=-1) {
    bool res = 0;

    for (int u:adj[v]) {
        if (u != p) res |= DFS(u, v);
    }

    if (res) return 0;

    if (v != 1) {
        swap(arr[v], arr[p]);
        ans++;
        return 1;
    }

    swap(arr[1], arr[adj[1][0]]);
    ans++;
    return 0;
}


void DFSsz(int v, int p=-1) {
    sz[v] = 1;

    for (int u:adj[v]) {
        if (u == p) continue;
        DFSsz(u, v);
        sz[v] += sz[u];
    }
}


int centroid(int tot, int v, int p=-1) {
    for (int u:adj[v]) {
        if (u != p && 2*sz[u] > tot) {
            return centroid(tot, u, v);
        }
    }

    return v;
}



vector<int> vec;
vector<pii> love;
pii tof;

void DFS2(int v, int p=-1) {
    vec.pb(v);
    
    for (int u:adj[v]) {
        if (u == p) continue;
        DFS2(u, v);
    }
}


void solve() {
    DFS2(cent);
    // cout << "$" << vec.size() << endl;

    for (int i=1; i<=n; i++) {
        arr4[vec[i-1]] = vec[(i-1+n/2)%n];
    }
}


int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    tof.F = -1;
 
    cin >> n;

    for (int i=1; i<n; i++) {
        cin >> u >> v;

        adj[u].pb(v);
        adj[v].pb(u);
    }

    // Min 
    for (int i=1; i<=n; i++) arr[i] = i;
    DFS(1);
    for (int i=1; i<=n; i++) arr2[arr[i]] = i;

    // Max
    DFSsz(1);
    cent = centroid(n, 1);
    DFSsz(cent);
    for (int i=1; i<=n; i++) arr3[i] = i;
    solve();

    // cout << "!" << cent << endl;

    for (int i=1; i<=n; i++) if (i != cent) ans2 += sz[i];
    // for (int i=1; i<=n; i++) arr4[arr3[i]] = i;

    cout << 2*ans << " " << 2*ans2 << endl;

    for (int i=1; i<=n; i++) cout << arr2[i] << " ";
    cout << endl;

    for (int i=1; i<=n; i++) cout << arr4[i] << " ";
    cout << endl;

 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4704 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4812 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4696 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4720 KB Output is correct
24 Correct 1 ms 4896 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4696 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4704 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4812 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4696 KB Output is correct
37 Correct 1 ms 4696 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4720 KB Output is correct
41 Correct 1 ms 4896 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4696 KB Output is correct
48 Correct 39 ms 9992 KB Output is correct
49 Correct 46 ms 10460 KB Output is correct
50 Correct 42 ms 10468 KB Output is correct
51 Correct 34 ms 9160 KB Output is correct
52 Correct 42 ms 10452 KB Output is correct
53 Correct 42 ms 9684 KB Output is correct
54 Correct 25 ms 10964 KB Output is correct
55 Partially correct 54 ms 17868 KB Partially correct
56 Partially correct 49 ms 13780 KB Partially correct
57 Correct 50 ms 12492 KB Output is correct
58 Correct 51 ms 11476 KB Output is correct
59 Correct 43 ms 10440 KB Output is correct
60 Correct 32 ms 10572 KB Output is correct
61 Correct 35 ms 10700 KB Output is correct
62 Correct 35 ms 10696 KB Output is correct
63 Correct 33 ms 10592 KB Output is correct
64 Correct 41 ms 10772 KB Output is correct
65 Correct 37 ms 10704 KB Output is correct
66 Correct 33 ms 10452 KB Output is correct
67 Correct 33 ms 9160 KB Output is correct
68 Correct 30 ms 9940 KB Output is correct
69 Correct 34 ms 10764 KB Output is correct
70 Correct 32 ms 10692 KB Output is correct
71 Correct 24 ms 8916 KB Output is correct
72 Correct 27 ms 9512 KB Output is correct
73 Correct 35 ms 10964 KB Output is correct
74 Correct 33 ms 10196 KB Output is correct
75 Correct 42 ms 10184 KB Output is correct
76 Correct 40 ms 10184 KB Output is correct
77 Correct 35 ms 10456 KB Output is correct
78 Correct 25 ms 8668 KB Output is correct
79 Correct 30 ms 9172 KB Output is correct
80 Correct 42 ms 10196 KB Output is correct
81 Correct 41 ms 10704 KB Output is correct
82 Correct 33 ms 10700 KB Output is correct