Submission #936307

# Submission time Handle Problem Language Result Execution time Memory
936307 2024-03-01T14:41:58 Z Darren0724 Village (BOI20_village) C++17
50 / 100
58 ms 20576 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
int n,mn=0,mx=0,total=0;
vector<int> adj[N],v(N),v1,sz(N,1);
vector<int> rec;
void dfs(int k,int pa){
    for(int j:adj[k]){
        if(j==pa)continue;
        dfs(j,k);
        if(v[j]==j){
            swap(v[j],v[k]);
            mn+=2;
        }
        sz[k]+=sz[j];
    }
}
int cen(int k,int pa){
    for(int j:adj[k]){
        if(j==pa)continue;
        if(sz[j]>n/2){
            return cen(j,k);
        }
    }
    return k;
}
void dfs1(int k,int pa,int deep){
    total+=deep*2;
    v1.push_back(k);
    for(int j:adj[k]){
        if(j==pa)continue;
        dfs1(j,k,deep+1);
    }
}
int32_t main() {
    LCBorz;
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    iota(all(v),0);
    dfs(1,1);
    if(v[1]==1){
        swap(v[1],v[adj[1][0]]);
        mn+=2;
    }
    int c=cen(1,1);
    dfs1(c,c,0);
    mx=total;
    rotate(v1.begin(),v1.begin()+n/2,v1.end());
    cout<<mn<<' '<<mx<<endl;
    for(int i=1;i<=n;i++){
        cout<<v[i]<<' ';
    }
    cout<<endl;
    for(int i=0;i<n;i++){
        cout<<v1[i]<<' ';
    }
    cout<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Partially correct 3 ms 8284 KB Partially correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8436 KB Output is correct
5 Partially correct 3 ms 8284 KB Partially correct
6 Partially correct 3 ms 8284 KB Partially correct
7 Partially correct 3 ms 8284 KB Partially correct
8 Partially correct 3 ms 8284 KB Partially correct
9 Partially correct 4 ms 8304 KB Partially correct
10 Partially correct 3 ms 8284 KB Partially correct
11 Partially correct 3 ms 8536 KB Partially correct
12 Partially correct 2 ms 8284 KB Partially correct
13 Partially correct 3 ms 8284 KB Partially correct
14 Partially correct 4 ms 8284 KB Partially correct
15 Correct 3 ms 8280 KB Output is correct
16 Partially correct 3 ms 8284 KB Partially correct
17 Partially correct 3 ms 8284 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 8280 KB Partially correct
2 Partially correct 4 ms 8284 KB Partially correct
3 Partially correct 3 ms 8284 KB Partially correct
4 Partially correct 3 ms 8284 KB Partially correct
5 Partially correct 3 ms 8284 KB Partially correct
6 Partially correct 3 ms 8284 KB Partially correct
7 Partially correct 3 ms 8284 KB Partially correct
8 Partially correct 4 ms 8284 KB Partially correct
9 Partially correct 3 ms 8284 KB Partially correct
10 Partially correct 3 ms 8280 KB Partially correct
11 Partially correct 4 ms 8284 KB Partially correct
12 Partially correct 3 ms 8284 KB Partially correct
13 Partially correct 3 ms 8536 KB Partially correct
14 Partially correct 3 ms 8304 KB Partially correct
15 Partially correct 3 ms 8288 KB Partially correct
16 Partially correct 3 ms 8280 KB Partially correct
17 Partially correct 3 ms 8284 KB Partially correct
18 Partially correct 3 ms 8280 KB Partially correct
19 Partially correct 3 ms 8284 KB Partially correct
20 Partially correct 3 ms 8284 KB Partially correct
21 Partially correct 3 ms 8284 KB Partially correct
22 Partially correct 3 ms 8284 KB Partially correct
23 Partially correct 3 ms 8284 KB Partially correct
24 Partially correct 3 ms 8284 KB Partially correct
25 Partially correct 3 ms 8284 KB Partially correct
26 Partially correct 3 ms 8284 KB Partially correct
27 Partially correct 3 ms 8284 KB Partially correct
28 Partially correct 4 ms 8300 KB Partially correct
29 Partially correct 4 ms 8536 KB Partially correct
30 Partially correct 3 ms 8284 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Partially correct 3 ms 8284 KB Partially correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8436 KB Output is correct
5 Partially correct 3 ms 8284 KB Partially correct
6 Partially correct 3 ms 8284 KB Partially correct
7 Partially correct 3 ms 8284 KB Partially correct
8 Partially correct 3 ms 8284 KB Partially correct
9 Partially correct 4 ms 8304 KB Partially correct
10 Partially correct 3 ms 8284 KB Partially correct
11 Partially correct 3 ms 8536 KB Partially correct
12 Partially correct 2 ms 8284 KB Partially correct
13 Partially correct 3 ms 8284 KB Partially correct
14 Partially correct 4 ms 8284 KB Partially correct
15 Correct 3 ms 8280 KB Output is correct
16 Partially correct 3 ms 8284 KB Partially correct
17 Partially correct 3 ms 8284 KB Partially correct
18 Partially correct 4 ms 8280 KB Partially correct
19 Partially correct 4 ms 8284 KB Partially correct
20 Partially correct 3 ms 8284 KB Partially correct
21 Partially correct 3 ms 8284 KB Partially correct
22 Partially correct 3 ms 8284 KB Partially correct
23 Partially correct 3 ms 8284 KB Partially correct
24 Partially correct 3 ms 8284 KB Partially correct
25 Partially correct 4 ms 8284 KB Partially correct
26 Partially correct 3 ms 8284 KB Partially correct
27 Partially correct 3 ms 8280 KB Partially correct
28 Partially correct 4 ms 8284 KB Partially correct
29 Partially correct 3 ms 8284 KB Partially correct
30 Partially correct 3 ms 8536 KB Partially correct
31 Partially correct 3 ms 8304 KB Partially correct
32 Partially correct 3 ms 8288 KB Partially correct
33 Partially correct 3 ms 8280 KB Partially correct
34 Partially correct 3 ms 8284 KB Partially correct
35 Partially correct 3 ms 8280 KB Partially correct
36 Partially correct 3 ms 8284 KB Partially correct
37 Partially correct 3 ms 8284 KB Partially correct
38 Partially correct 3 ms 8284 KB Partially correct
39 Partially correct 3 ms 8284 KB Partially correct
40 Partially correct 3 ms 8284 KB Partially correct
41 Partially correct 3 ms 8284 KB Partially correct
42 Partially correct 3 ms 8284 KB Partially correct
43 Partially correct 3 ms 8284 KB Partially correct
44 Partially correct 3 ms 8284 KB Partially correct
45 Partially correct 4 ms 8300 KB Partially correct
46 Partially correct 4 ms 8536 KB Partially correct
47 Partially correct 3 ms 8284 KB Partially correct
48 Partially correct 40 ms 14552 KB Partially correct
49 Partially correct 44 ms 15164 KB Partially correct
50 Partially correct 45 ms 15264 KB Partially correct
51 Partially correct 33 ms 13764 KB Partially correct
52 Partially correct 47 ms 15044 KB Partially correct
53 Partially correct 52 ms 14532 KB Partially correct
54 Partially correct 25 ms 14284 KB Partially correct
55 Partially correct 50 ms 20576 KB Partially correct
56 Partially correct 58 ms 18120 KB Partially correct
57 Partially correct 45 ms 16852 KB Partially correct
58 Partially correct 51 ms 16004 KB Partially correct
59 Partially correct 49 ms 15192 KB Partially correct
60 Correct 36 ms 15176 KB Output is correct
61 Partially correct 36 ms 15292 KB Partially correct
62 Partially correct 46 ms 15888 KB Partially correct
63 Partially correct 35 ms 15044 KB Partially correct
64 Partially correct 38 ms 15560 KB Partially correct
65 Partially correct 41 ms 15816 KB Partially correct
66 Partially correct 41 ms 15044 KB Partially correct
67 Partially correct 30 ms 13764 KB Partially correct
68 Partially correct 32 ms 14548 KB Partially correct
69 Partially correct 39 ms 15816 KB Partially correct
70 Partially correct 37 ms 15308 KB Partially correct
71 Partially correct 28 ms 13516 KB Partially correct
72 Partially correct 31 ms 14280 KB Partially correct
73 Partially correct 38 ms 15824 KB Partially correct
74 Partially correct 34 ms 15048 KB Partially correct
75 Partially correct 46 ms 15564 KB Partially correct
76 Partially correct 39 ms 15044 KB Partially correct
77 Partially correct 40 ms 15560 KB Partially correct
78 Partially correct 27 ms 13008 KB Partially correct
79 Partially correct 31 ms 13780 KB Partially correct
80 Partially correct 42 ms 15564 KB Partially correct
81 Partially correct 40 ms 15568 KB Partially correct
82 Partially correct 37 ms 15308 KB Partially correct