#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(N),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;
rec.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;
for(int i=0;i<n;i++){
v1[rec[(i+n/2)%n]]=rec[i];
}
cout<<mn<<' '<<mx<<endl;
for(int i=1;i<=n;i++){
cout<<v[i]<<' ';
}
cout<<endl;
for(int i=1;i<=n;i++){
cout<<v1[i]<<' ';
}
cout<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
4 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
3 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
4 ms |
9820 KB |
Output is correct |
12 |
Correct |
3 ms |
9816 KB |
Output is correct |
13 |
Correct |
4 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
4 ms |
9820 KB |
Output is correct |
16 |
Correct |
5 ms |
10076 KB |
Output is correct |
17 |
Correct |
4 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
4 ms |
9816 KB |
Output is correct |
4 |
Correct |
4 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9816 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9896 KB |
Output is correct |
11 |
Correct |
4 ms |
9820 KB |
Output is correct |
12 |
Correct |
4 ms |
9820 KB |
Output is correct |
13 |
Correct |
5 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
5 ms |
9816 KB |
Output is correct |
16 |
Correct |
4 ms |
9820 KB |
Output is correct |
17 |
Correct |
4 ms |
9820 KB |
Output is correct |
18 |
Correct |
4 ms |
9816 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9816 KB |
Output is correct |
22 |
Correct |
4 ms |
9820 KB |
Output is correct |
23 |
Correct |
4 ms |
9820 KB |
Output is correct |
24 |
Correct |
4 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
9820 KB |
Output is correct |
26 |
Correct |
4 ms |
9820 KB |
Output is correct |
27 |
Correct |
4 ms |
9820 KB |
Output is correct |
28 |
Correct |
4 ms |
9820 KB |
Output is correct |
29 |
Correct |
4 ms |
9820 KB |
Output is correct |
30 |
Correct |
4 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
4 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9820 KB |
Output is correct |
9 |
Correct |
3 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
4 ms |
9820 KB |
Output is correct |
12 |
Correct |
3 ms |
9816 KB |
Output is correct |
13 |
Correct |
4 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
4 ms |
9820 KB |
Output is correct |
16 |
Correct |
5 ms |
10076 KB |
Output is correct |
17 |
Correct |
4 ms |
9820 KB |
Output is correct |
18 |
Correct |
4 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9816 KB |
Output is correct |
20 |
Correct |
4 ms |
9816 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
4 ms |
9820 KB |
Output is correct |
23 |
Correct |
4 ms |
9820 KB |
Output is correct |
24 |
Correct |
4 ms |
9816 KB |
Output is correct |
25 |
Correct |
4 ms |
9820 KB |
Output is correct |
26 |
Correct |
4 ms |
9820 KB |
Output is correct |
27 |
Correct |
4 ms |
9896 KB |
Output is correct |
28 |
Correct |
4 ms |
9820 KB |
Output is correct |
29 |
Correct |
4 ms |
9820 KB |
Output is correct |
30 |
Correct |
5 ms |
9820 KB |
Output is correct |
31 |
Correct |
4 ms |
9820 KB |
Output is correct |
32 |
Correct |
5 ms |
9816 KB |
Output is correct |
33 |
Correct |
4 ms |
9820 KB |
Output is correct |
34 |
Correct |
4 ms |
9820 KB |
Output is correct |
35 |
Correct |
4 ms |
9816 KB |
Output is correct |
36 |
Correct |
4 ms |
9820 KB |
Output is correct |
37 |
Correct |
4 ms |
9820 KB |
Output is correct |
38 |
Correct |
4 ms |
9816 KB |
Output is correct |
39 |
Correct |
4 ms |
9820 KB |
Output is correct |
40 |
Correct |
4 ms |
9820 KB |
Output is correct |
41 |
Correct |
4 ms |
9820 KB |
Output is correct |
42 |
Correct |
4 ms |
9820 KB |
Output is correct |
43 |
Correct |
4 ms |
9820 KB |
Output is correct |
44 |
Correct |
4 ms |
9820 KB |
Output is correct |
45 |
Correct |
4 ms |
9820 KB |
Output is correct |
46 |
Correct |
4 ms |
9820 KB |
Output is correct |
47 |
Correct |
4 ms |
9820 KB |
Output is correct |
48 |
Correct |
41 ms |
16236 KB |
Output is correct |
49 |
Correct |
51 ms |
16840 KB |
Output is correct |
50 |
Correct |
48 ms |
16840 KB |
Output is correct |
51 |
Correct |
35 ms |
15300 KB |
Output is correct |
52 |
Correct |
44 ms |
16580 KB |
Output is correct |
53 |
Correct |
42 ms |
15908 KB |
Output is correct |
54 |
Correct |
31 ms |
15820 KB |
Output is correct |
55 |
Correct |
74 ms |
22256 KB |
Output is correct |
56 |
Correct |
65 ms |
19400 KB |
Output is correct |
57 |
Correct |
50 ms |
18384 KB |
Output is correct |
58 |
Correct |
48 ms |
17760 KB |
Output is correct |
59 |
Correct |
47 ms |
16840 KB |
Output is correct |
60 |
Correct |
35 ms |
16712 KB |
Output is correct |
61 |
Correct |
36 ms |
16828 KB |
Output is correct |
62 |
Correct |
40 ms |
17092 KB |
Output is correct |
63 |
Correct |
37 ms |
16704 KB |
Output is correct |
64 |
Correct |
41 ms |
17096 KB |
Output is correct |
65 |
Correct |
38 ms |
17352 KB |
Output is correct |
66 |
Correct |
36 ms |
16580 KB |
Output is correct |
67 |
Correct |
30 ms |
15156 KB |
Output is correct |
68 |
Correct |
33 ms |
16080 KB |
Output is correct |
69 |
Correct |
48 ms |
17288 KB |
Output is correct |
70 |
Correct |
36 ms |
16848 KB |
Output is correct |
71 |
Correct |
28 ms |
15048 KB |
Output is correct |
72 |
Correct |
34 ms |
15568 KB |
Output is correct |
73 |
Correct |
43 ms |
17344 KB |
Output is correct |
74 |
Correct |
38 ms |
16592 KB |
Output is correct |
75 |
Correct |
46 ms |
17096 KB |
Output is correct |
76 |
Correct |
42 ms |
16584 KB |
Output is correct |
77 |
Correct |
58 ms |
17140 KB |
Output is correct |
78 |
Correct |
34 ms |
14712 KB |
Output is correct |
79 |
Correct |
37 ms |
15380 KB |
Output is correct |
80 |
Correct |
46 ms |
17104 KB |
Output is correct |
81 |
Correct |
41 ms |
17356 KB |
Output is correct |
82 |
Correct |
41 ms |
16840 KB |
Output is correct |