#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ar array
#define ld long double
const int N = 3e5 + 20;
const int K = 200;
const int INF = 1e15;
const int LOG = 24;
const int MOD = 998244353;
vector<int> g[N], ord;
int n, posLo[N], posHi[N], ansLo, ansHi, sz[N];
void dfs(int x,int p)
{
sz[x] = 1;
ord.push_back(x);
for(auto u: g[x])
{
if(u == p)
continue;
dfs(u, x);
sz[x] += sz[u];
ansHi += min(sz[u], n - sz[u]);
}
if(posLo[x] == x)
{
if(p == -1)
swap(posLo[x], posLo[g[x][0]]);
else
swap(posLo[x], posLo[p]);
ansLo += 2;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i < n; i++)
{
int u, v;
cin>>u>>v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 0; i < n; i ++)
posLo[i] = i;
dfs(0, -1);
ansHi *= 2;
for(int i = 0; i < n; i++)
{
int u = ord[i];
int v = ord[(i + n / 2) % n];
posHi[u] = v;
}
cout << ansLo << " " << ansHi << '\n';
for(int i = 0; i < n; i ++)
cout << posLo[i] + 1 << " ";
cout << '\n';
for(int i = 0; i < n; i ++)
cout << posHi[i] + 1 << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10072 KB |
Output is correct |
2 |
Correct |
3 ms |
8028 KB |
Output is correct |
3 |
Correct |
2 ms |
10076 KB |
Output is correct |
4 |
Correct |
2 ms |
10076 KB |
Output is correct |
5 |
Correct |
2 ms |
10264 KB |
Output is correct |
6 |
Correct |
2 ms |
10076 KB |
Output is correct |
7 |
Correct |
2 ms |
10076 KB |
Output is correct |
8 |
Correct |
2 ms |
10072 KB |
Output is correct |
9 |
Correct |
3 ms |
8028 KB |
Output is correct |
10 |
Correct |
3 ms |
8028 KB |
Output is correct |
11 |
Correct |
3 ms |
10172 KB |
Output is correct |
12 |
Correct |
2 ms |
10076 KB |
Output is correct |
13 |
Correct |
2 ms |
10076 KB |
Output is correct |
14 |
Correct |
3 ms |
10256 KB |
Output is correct |
15 |
Correct |
2 ms |
10076 KB |
Output is correct |
16 |
Correct |
2 ms |
10076 KB |
Output is correct |
17 |
Correct |
3 ms |
8216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10076 KB |
Output is correct |
2 |
Correct |
2 ms |
10076 KB |
Output is correct |
3 |
Correct |
2 ms |
10072 KB |
Output is correct |
4 |
Correct |
4 ms |
8284 KB |
Output is correct |
5 |
Correct |
3 ms |
10332 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
3 ms |
8284 KB |
Output is correct |
10 |
Correct |
3 ms |
8284 KB |
Output is correct |
11 |
Correct |
3 ms |
10332 KB |
Output is correct |
12 |
Correct |
2 ms |
10332 KB |
Output is correct |
13 |
Correct |
3 ms |
10328 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
3 ms |
8284 KB |
Output is correct |
16 |
Correct |
2 ms |
10332 KB |
Output is correct |
17 |
Correct |
3 ms |
8284 KB |
Output is correct |
18 |
Correct |
3 ms |
8212 KB |
Output is correct |
19 |
Correct |
3 ms |
10328 KB |
Output is correct |
20 |
Correct |
3 ms |
10332 KB |
Output is correct |
21 |
Correct |
3 ms |
10332 KB |
Output is correct |
22 |
Correct |
2 ms |
10332 KB |
Output is correct |
23 |
Correct |
3 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
3 ms |
8028 KB |
Output is correct |
26 |
Correct |
3 ms |
8284 KB |
Output is correct |
27 |
Correct |
2 ms |
10076 KB |
Output is correct |
28 |
Correct |
2 ms |
10332 KB |
Output is correct |
29 |
Correct |
3 ms |
10332 KB |
Output is correct |
30 |
Correct |
2 ms |
10332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10072 KB |
Output is correct |
2 |
Correct |
3 ms |
8028 KB |
Output is correct |
3 |
Correct |
2 ms |
10076 KB |
Output is correct |
4 |
Correct |
2 ms |
10076 KB |
Output is correct |
5 |
Correct |
2 ms |
10264 KB |
Output is correct |
6 |
Correct |
2 ms |
10076 KB |
Output is correct |
7 |
Correct |
2 ms |
10076 KB |
Output is correct |
8 |
Correct |
2 ms |
10072 KB |
Output is correct |
9 |
Correct |
3 ms |
8028 KB |
Output is correct |
10 |
Correct |
3 ms |
8028 KB |
Output is correct |
11 |
Correct |
3 ms |
10172 KB |
Output is correct |
12 |
Correct |
2 ms |
10076 KB |
Output is correct |
13 |
Correct |
2 ms |
10076 KB |
Output is correct |
14 |
Correct |
3 ms |
10256 KB |
Output is correct |
15 |
Correct |
2 ms |
10076 KB |
Output is correct |
16 |
Correct |
2 ms |
10076 KB |
Output is correct |
17 |
Correct |
3 ms |
8216 KB |
Output is correct |
18 |
Correct |
2 ms |
10076 KB |
Output is correct |
19 |
Correct |
2 ms |
10076 KB |
Output is correct |
20 |
Correct |
2 ms |
10072 KB |
Output is correct |
21 |
Correct |
4 ms |
8284 KB |
Output is correct |
22 |
Correct |
3 ms |
10332 KB |
Output is correct |
23 |
Correct |
3 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
26 |
Correct |
3 ms |
8284 KB |
Output is correct |
27 |
Correct |
3 ms |
8284 KB |
Output is correct |
28 |
Correct |
3 ms |
10332 KB |
Output is correct |
29 |
Correct |
2 ms |
10332 KB |
Output is correct |
30 |
Correct |
3 ms |
10328 KB |
Output is correct |
31 |
Correct |
4 ms |
8284 KB |
Output is correct |
32 |
Correct |
3 ms |
8284 KB |
Output is correct |
33 |
Correct |
2 ms |
10332 KB |
Output is correct |
34 |
Correct |
3 ms |
8284 KB |
Output is correct |
35 |
Correct |
3 ms |
8212 KB |
Output is correct |
36 |
Correct |
3 ms |
10328 KB |
Output is correct |
37 |
Correct |
3 ms |
10332 KB |
Output is correct |
38 |
Correct |
3 ms |
10332 KB |
Output is correct |
39 |
Correct |
2 ms |
10332 KB |
Output is correct |
40 |
Correct |
3 ms |
8284 KB |
Output is correct |
41 |
Correct |
4 ms |
8284 KB |
Output is correct |
42 |
Correct |
3 ms |
8028 KB |
Output is correct |
43 |
Correct |
3 ms |
8284 KB |
Output is correct |
44 |
Correct |
2 ms |
10076 KB |
Output is correct |
45 |
Correct |
2 ms |
10332 KB |
Output is correct |
46 |
Correct |
3 ms |
10332 KB |
Output is correct |
47 |
Correct |
2 ms |
10332 KB |
Output is correct |
48 |
Correct |
34 ms |
17916 KB |
Output is correct |
49 |
Correct |
37 ms |
18628 KB |
Output is correct |
50 |
Correct |
38 ms |
18664 KB |
Output is correct |
51 |
Correct |
34 ms |
16952 KB |
Output is correct |
52 |
Correct |
37 ms |
18628 KB |
Output is correct |
53 |
Correct |
34 ms |
17864 KB |
Output is correct |
54 |
Correct |
22 ms |
17624 KB |
Output is correct |
55 |
Correct |
43 ms |
25544 KB |
Output is correct |
56 |
Correct |
43 ms |
22212 KB |
Output is correct |
57 |
Correct |
38 ms |
20940 KB |
Output is correct |
58 |
Correct |
40 ms |
19916 KB |
Output is correct |
59 |
Correct |
36 ms |
18888 KB |
Output is correct |
60 |
Correct |
31 ms |
18760 KB |
Output is correct |
61 |
Correct |
34 ms |
18876 KB |
Output is correct |
62 |
Correct |
37 ms |
19152 KB |
Output is correct |
63 |
Correct |
31 ms |
18632 KB |
Output is correct |
64 |
Correct |
36 ms |
19144 KB |
Output is correct |
65 |
Correct |
34 ms |
19132 KB |
Output is correct |
66 |
Correct |
31 ms |
18632 KB |
Output is correct |
67 |
Correct |
25 ms |
16848 KB |
Output is correct |
68 |
Correct |
31 ms |
17860 KB |
Output is correct |
69 |
Correct |
36 ms |
19408 KB |
Output is correct |
70 |
Correct |
29 ms |
18720 KB |
Output is correct |
71 |
Correct |
25 ms |
16584 KB |
Output is correct |
72 |
Correct |
26 ms |
17360 KB |
Output is correct |
73 |
Correct |
34 ms |
19408 KB |
Output is correct |
74 |
Correct |
28 ms |
18372 KB |
Output is correct |
75 |
Correct |
38 ms |
19148 KB |
Output is correct |
76 |
Correct |
35 ms |
18500 KB |
Output is correct |
77 |
Correct |
36 ms |
19092 KB |
Output is correct |
78 |
Correct |
23 ms |
16080 KB |
Output is correct |
79 |
Correct |
27 ms |
16840 KB |
Output is correct |
80 |
Correct |
38 ms |
19152 KB |
Output is correct |
81 |
Correct |
33 ms |
19148 KB |
Output is correct |
82 |
Correct |
32 ms |
18888 KB |
Output is correct |