Submission #896172

# Submission time Handle Problem Language Result Execution time Memory
896172 2024-01-01T00:01:07 Z ShaShi Village (BOI20_village) C++17
75 / 100
54 ms 17740 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);
    }
}


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);
    DFS2(cent);

    for (int i=0; i<n; i++) {
        arr3[vec[i]] = vec[(i+(n/2))%n];
    }
    for (int i=1; i<=n; i++) if (i != cent) ans2 += sz[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 << arr3[i] << " ";
    cout << endl;

 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4956 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 4712 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 4700 KB Output is correct
# Verdict Execution time Memory 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 4696 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 4708 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 4696 KB Output is correct
16 Correct 1 ms 4700 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 4952 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4696 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 4696 KB Output is correct
29 Correct 1 ms 4696 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4956 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 4712 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 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 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 4708 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 4696 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4952 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4696 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 1 ms 4696 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 4696 KB Output is correct
46 Correct 1 ms 4696 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 39 ms 9940 KB Output is correct
49 Correct 44 ms 10260 KB Output is correct
50 Correct 43 ms 10448 KB Output is correct
51 Correct 33 ms 9164 KB Output is correct
52 Correct 44 ms 10440 KB Output is correct
53 Correct 44 ms 9740 KB Output is correct
54 Correct 28 ms 10972 KB Output is correct
55 Partially correct 54 ms 17740 KB Partially correct
56 Partially correct 52 ms 13772 KB Partially correct
57 Correct 49 ms 12492 KB Output is correct
58 Correct 50 ms 11600 KB Output is correct
59 Correct 44 ms 10440 KB Output is correct
60 Correct 32 ms 10576 KB Output is correct
61 Correct 35 ms 10708 KB Output is correct
62 Correct 42 ms 10700 KB Output is correct
63 Correct 35 ms 10456 KB Output is correct
64 Correct 38 ms 10568 KB Output is correct
65 Correct 35 ms 10712 KB Output is correct
66 Correct 37 ms 10320 KB Output is correct
67 Correct 26 ms 9164 KB Output is correct
68 Correct 35 ms 9928 KB Output is correct
69 Correct 35 ms 10964 KB Output is correct
70 Correct 32 ms 10440 KB Output is correct
71 Correct 25 ms 8916 KB Output is correct
72 Correct 27 ms 9420 KB Output is correct
73 Correct 34 ms 10964 KB Output is correct
74 Correct 33 ms 10184 KB Output is correct
75 Correct 43 ms 10192 KB Output is correct
76 Correct 40 ms 10312 KB Output is correct
77 Correct 40 ms 10524 KB Output is correct
78 Correct 25 ms 8664 KB Output is correct
79 Correct 32 ms 9164 KB Output is correct
80 Correct 41 ms 10192 KB Output is correct
81 Correct 38 ms 10716 KB Output is correct
82 Correct 35 ms 10544 KB Output is correct