#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
int n;
vector<int> graph[maxn];
ll mn=0, mx=0;
vector<int> ansMn(maxn), ansMx(maxn), sub(maxn), euler;
void dfs(int u, int p) {
sub[u] = 1;
euler.push_back(u);
for(int &v : graph[u]) {
if(v == p) continue;
dfs(v, u);
sub[u] += sub[v];
}
mx += min(sub[u], n - sub[u]);
if(u == ansMn[u]) {
mn += 2;
if(p) swap(ansMn[u], ansMn[p]);
else swap(ansMn[u], ansMn[graph[u].back()]);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
cin >> n;
for(int i=1; i<=n; i++) ansMn[i] = ansMx[i] = i;
for(int i=0; i<n-1; i++) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
dfs(1, 0);
cout << mn << " " << 2 * mx << '\n';
for(int i=0; i<n; i++) ansMx[euler[i]] = euler[(i+n/2)%n];
for(int i=1; i<=n; i++) cout << ansMn[i] << " ";
cout << '\n';
for(int i=1; i<=n; i++) cout << ansMx[i] << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3928 KB |
Output is correct |
2 |
Correct |
1 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3932 KB |
Output is correct |
4 |
Correct |
1 ms |
3928 KB |
Output is correct |
5 |
Correct |
1 ms |
3928 KB |
Output is correct |
6 |
Correct |
1 ms |
3932 KB |
Output is correct |
7 |
Correct |
1 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
3932 KB |
Output is correct |
9 |
Correct |
1 ms |
3936 KB |
Output is correct |
10 |
Correct |
1 ms |
3932 KB |
Output is correct |
11 |
Correct |
1 ms |
3928 KB |
Output is correct |
12 |
Correct |
1 ms |
3932 KB |
Output is correct |
13 |
Correct |
1 ms |
3944 KB |
Output is correct |
14 |
Correct |
1 ms |
3932 KB |
Output is correct |
15 |
Correct |
1 ms |
3932 KB |
Output is correct |
16 |
Correct |
1 ms |
3932 KB |
Output is correct |
17 |
Correct |
1 ms |
3928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3932 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3940 KB |
Output is correct |
4 |
Correct |
2 ms |
3932 KB |
Output is correct |
5 |
Correct |
1 ms |
3932 KB |
Output is correct |
6 |
Correct |
1 ms |
3932 KB |
Output is correct |
7 |
Correct |
1 ms |
3932 KB |
Output is correct |
8 |
Correct |
1 ms |
3932 KB |
Output is correct |
9 |
Correct |
2 ms |
3932 KB |
Output is correct |
10 |
Correct |
2 ms |
3932 KB |
Output is correct |
11 |
Correct |
1 ms |
3808 KB |
Output is correct |
12 |
Correct |
1 ms |
3932 KB |
Output is correct |
13 |
Correct |
2 ms |
4188 KB |
Output is correct |
14 |
Correct |
1 ms |
3932 KB |
Output is correct |
15 |
Correct |
1 ms |
3932 KB |
Output is correct |
16 |
Correct |
1 ms |
3932 KB |
Output is correct |
17 |
Correct |
1 ms |
3932 KB |
Output is correct |
18 |
Correct |
1 ms |
3932 KB |
Output is correct |
19 |
Correct |
1 ms |
3932 KB |
Output is correct |
20 |
Correct |
2 ms |
3932 KB |
Output is correct |
21 |
Correct |
2 ms |
4188 KB |
Output is correct |
22 |
Correct |
2 ms |
3928 KB |
Output is correct |
23 |
Correct |
2 ms |
3932 KB |
Output is correct |
24 |
Correct |
1 ms |
3932 KB |
Output is correct |
25 |
Correct |
1 ms |
3932 KB |
Output is correct |
26 |
Correct |
1 ms |
3932 KB |
Output is correct |
27 |
Correct |
1 ms |
3932 KB |
Output is correct |
28 |
Correct |
2 ms |
3932 KB |
Output is correct |
29 |
Correct |
1 ms |
3928 KB |
Output is correct |
30 |
Correct |
2 ms |
3928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3928 KB |
Output is correct |
2 |
Correct |
1 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3932 KB |
Output is correct |
4 |
Correct |
1 ms |
3928 KB |
Output is correct |
5 |
Correct |
1 ms |
3928 KB |
Output is correct |
6 |
Correct |
1 ms |
3932 KB |
Output is correct |
7 |
Correct |
1 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
3932 KB |
Output is correct |
9 |
Correct |
1 ms |
3936 KB |
Output is correct |
10 |
Correct |
1 ms |
3932 KB |
Output is correct |
11 |
Correct |
1 ms |
3928 KB |
Output is correct |
12 |
Correct |
1 ms |
3932 KB |
Output is correct |
13 |
Correct |
1 ms |
3944 KB |
Output is correct |
14 |
Correct |
1 ms |
3932 KB |
Output is correct |
15 |
Correct |
1 ms |
3932 KB |
Output is correct |
16 |
Correct |
1 ms |
3932 KB |
Output is correct |
17 |
Correct |
1 ms |
3928 KB |
Output is correct |
18 |
Correct |
1 ms |
3932 KB |
Output is correct |
19 |
Correct |
2 ms |
3932 KB |
Output is correct |
20 |
Correct |
1 ms |
3940 KB |
Output is correct |
21 |
Correct |
2 ms |
3932 KB |
Output is correct |
22 |
Correct |
1 ms |
3932 KB |
Output is correct |
23 |
Correct |
1 ms |
3932 KB |
Output is correct |
24 |
Correct |
1 ms |
3932 KB |
Output is correct |
25 |
Correct |
1 ms |
3932 KB |
Output is correct |
26 |
Correct |
2 ms |
3932 KB |
Output is correct |
27 |
Correct |
2 ms |
3932 KB |
Output is correct |
28 |
Correct |
1 ms |
3808 KB |
Output is correct |
29 |
Correct |
1 ms |
3932 KB |
Output is correct |
30 |
Correct |
2 ms |
4188 KB |
Output is correct |
31 |
Correct |
1 ms |
3932 KB |
Output is correct |
32 |
Correct |
1 ms |
3932 KB |
Output is correct |
33 |
Correct |
1 ms |
3932 KB |
Output is correct |
34 |
Correct |
1 ms |
3932 KB |
Output is correct |
35 |
Correct |
1 ms |
3932 KB |
Output is correct |
36 |
Correct |
1 ms |
3932 KB |
Output is correct |
37 |
Correct |
2 ms |
3932 KB |
Output is correct |
38 |
Correct |
2 ms |
4188 KB |
Output is correct |
39 |
Correct |
2 ms |
3928 KB |
Output is correct |
40 |
Correct |
2 ms |
3932 KB |
Output is correct |
41 |
Correct |
1 ms |
3932 KB |
Output is correct |
42 |
Correct |
1 ms |
3932 KB |
Output is correct |
43 |
Correct |
1 ms |
3932 KB |
Output is correct |
44 |
Correct |
1 ms |
3932 KB |
Output is correct |
45 |
Correct |
2 ms |
3932 KB |
Output is correct |
46 |
Correct |
1 ms |
3928 KB |
Output is correct |
47 |
Correct |
2 ms |
3928 KB |
Output is correct |
48 |
Correct |
35 ms |
9176 KB |
Output is correct |
49 |
Correct |
36 ms |
9680 KB |
Output is correct |
50 |
Correct |
33 ms |
9504 KB |
Output is correct |
51 |
Correct |
26 ms |
8660 KB |
Output is correct |
52 |
Correct |
33 ms |
9420 KB |
Output is correct |
53 |
Correct |
30 ms |
9168 KB |
Output is correct |
54 |
Correct |
19 ms |
9684 KB |
Output is correct |
55 |
Correct |
37 ms |
15564 KB |
Output is correct |
56 |
Correct |
36 ms |
12232 KB |
Output is correct |
57 |
Correct |
39 ms |
11724 KB |
Output is correct |
58 |
Correct |
34 ms |
10904 KB |
Output is correct |
59 |
Correct |
36 ms |
9936 KB |
Output is correct |
60 |
Correct |
29 ms |
10068 KB |
Output is correct |
61 |
Correct |
31 ms |
10316 KB |
Output is correct |
62 |
Correct |
35 ms |
10404 KB |
Output is correct |
63 |
Correct |
30 ms |
9952 KB |
Output is correct |
64 |
Correct |
31 ms |
10196 KB |
Output is correct |
65 |
Correct |
34 ms |
10464 KB |
Output is correct |
66 |
Correct |
30 ms |
10116 KB |
Output is correct |
67 |
Correct |
28 ms |
8704 KB |
Output is correct |
68 |
Correct |
27 ms |
9416 KB |
Output is correct |
69 |
Correct |
29 ms |
10488 KB |
Output is correct |
70 |
Correct |
27 ms |
9924 KB |
Output is correct |
71 |
Correct |
21 ms |
8392 KB |
Output is correct |
72 |
Correct |
24 ms |
8912 KB |
Output is correct |
73 |
Correct |
30 ms |
10440 KB |
Output is correct |
74 |
Correct |
27 ms |
9940 KB |
Output is correct |
75 |
Correct |
46 ms |
9776 KB |
Output is correct |
76 |
Correct |
32 ms |
9828 KB |
Output is correct |
77 |
Correct |
30 ms |
10188 KB |
Output is correct |
78 |
Correct |
23 ms |
8148 KB |
Output is correct |
79 |
Correct |
26 ms |
8648 KB |
Output is correct |
80 |
Correct |
37 ms |
9724 KB |
Output is correct |
81 |
Correct |
32 ms |
10204 KB |
Output is correct |
82 |
Correct |
32 ms |
10272 KB |
Output is correct |