#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
int sizee[MAX_N + 1], depth[MAX_N + 1], pairr[MAX_N + 1];
vector<int> adj[MAX_N + 1];
int n;
int c;
void findCentroid( int u, int p ) {
int maxSizee = 0;
sizee[u] = 1;
for ( int v: adj[u] ) {
if ( v == p )
continue;
findCentroid( v, u );
sizee[u] += sizee[v];
maxSizee = max( maxSizee, sizee[v] );
}
maxSizee = max( maxSizee, n - sizee[u] );
if ( maxSizee <= n / 2 )
c = u;
}
void calcSizes( int u, int p ) {
sizee[u] = 1;
for ( int v: adj[u] ) {
if ( v == p )
continue;
calcSizes( v, u );
sizee[u] += sizee[v];
}
}
long long maxSumDist;
vector<int> vert;
void dfs( int u, int p ) {
depth[u] = depth[p] + 1;
maxSumDist += depth[u];
for ( int v: adj[u] ) {
if ( v == p )
continue;
dfs( v, u );
}
vert.push_back( u );
}
int main() {
cin >> n;
for ( int i = 0; i < n - 1; i++ ) {
int u, v;
cin >> u >> v;
adj[u].push_back( v );
adj[v].push_back( u );
}
findCentroid( 1, 0 );
depth[0] = -1;
dfs( c, 0 );
for ( int i = 0; i < n / 2; i++ ) {
pairr[vert[i]] = vert[n / 2 + i];
pairr[vert[n / 2 + i]] = vert[i];
}
if ( pairr[c] == 0 ) {
int a = adj[c][0], b = pairr[a];
pairr[a] = b;
pairr[b] = c;
pairr[c] = a;
}
cout << 1 << " " << 2 * maxSumDist << "\n";
for ( int v = 1; v <= n; v++ )
cout << v << " ";
cout << "\n";
for ( int v = 1; v <= n; v++ )
cout << pairr[v] << " ";
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
2 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
4 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
5 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
6 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
7 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
8 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
9 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
10 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
11 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
12 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
13 |
Partially correct |
1 ms |
2648 KB |
Partially correct |
14 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
15 |
Partially correct |
1 ms |
2656 KB |
Partially correct |
16 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
17 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
4 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
5 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
6 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
7 |
Partially correct |
1 ms |
2908 KB |
Partially correct |
8 |
Partially correct |
1 ms |
2796 KB |
Partially correct |
9 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
10 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
11 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
12 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
13 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
14 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
15 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
16 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
17 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
18 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
19 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
20 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
21 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
22 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
23 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
24 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
25 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
26 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
27 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
28 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
29 |
Partially correct |
1 ms |
2796 KB |
Partially correct |
30 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
2 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
4 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
5 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
6 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
7 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
8 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
9 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
10 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
11 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
12 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
13 |
Partially correct |
1 ms |
2648 KB |
Partially correct |
14 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
15 |
Partially correct |
1 ms |
2656 KB |
Partially correct |
16 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
17 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
18 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
19 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
20 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
21 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
22 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
23 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
24 |
Partially correct |
1 ms |
2908 KB |
Partially correct |
25 |
Partially correct |
1 ms |
2796 KB |
Partially correct |
26 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
27 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
28 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
29 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
30 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
31 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
32 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
33 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
34 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
35 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
36 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
37 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
38 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
39 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
40 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
41 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
42 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
43 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
44 |
Partially correct |
1 ms |
2652 KB |
Partially correct |
45 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
46 |
Partially correct |
1 ms |
2796 KB |
Partially correct |
47 |
Partially correct |
2 ms |
2652 KB |
Partially correct |
48 |
Partially correct |
61 ms |
9368 KB |
Partially correct |
49 |
Partially correct |
75 ms |
10036 KB |
Partially correct |
50 |
Partially correct |
68 ms |
9860 KB |
Partially correct |
51 |
Partially correct |
52 ms |
8300 KB |
Partially correct |
52 |
Partially correct |
67 ms |
9988 KB |
Partially correct |
53 |
Partially correct |
67 ms |
9676 KB |
Partially correct |
54 |
Partially correct |
38 ms |
9800 KB |
Partially correct |
55 |
Partially correct |
80 ms |
17368 KB |
Partially correct |
56 |
Partially correct |
72 ms |
13268 KB |
Partially correct |
57 |
Partially correct |
70 ms |
12236 KB |
Partially correct |
58 |
Partially correct |
70 ms |
11084 KB |
Partially correct |
59 |
Partially correct |
76 ms |
10196 KB |
Partially correct |
60 |
Partially correct |
59 ms |
10208 KB |
Partially correct |
61 |
Partially correct |
62 ms |
10188 KB |
Partially correct |
62 |
Partially correct |
87 ms |
10284 KB |
Partially correct |
63 |
Partially correct |
59 ms |
9752 KB |
Partially correct |
64 |
Partially correct |
72 ms |
10188 KB |
Partially correct |
65 |
Partially correct |
70 ms |
10448 KB |
Partially correct |
66 |
Partially correct |
94 ms |
9856 KB |
Partially correct |
67 |
Partially correct |
55 ms |
8404 KB |
Partially correct |
68 |
Partially correct |
53 ms |
9168 KB |
Partially correct |
69 |
Partially correct |
62 ms |
10508 KB |
Partially correct |
70 |
Partially correct |
58 ms |
9932 KB |
Partially correct |
71 |
Partially correct |
43 ms |
8180 KB |
Partially correct |
72 |
Partially correct |
49 ms |
8780 KB |
Partially correct |
73 |
Partially correct |
61 ms |
10404 KB |
Partially correct |
74 |
Partially correct |
57 ms |
9928 KB |
Partially correct |
75 |
Partially correct |
69 ms |
9820 KB |
Partially correct |
76 |
Partially correct |
65 ms |
9760 KB |
Partially correct |
77 |
Partially correct |
62 ms |
10112 KB |
Partially correct |
78 |
Partially correct |
44 ms |
7744 KB |
Partially correct |
79 |
Partially correct |
50 ms |
8412 KB |
Partially correct |
80 |
Partially correct |
70 ms |
9684 KB |
Partially correct |
81 |
Partially correct |
63 ms |
10188 KB |
Partially correct |
82 |
Partially correct |
62 ms |
10060 KB |
Partially correct |