#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define VietAnh "Village"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
using namespace std;
const ll mod = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
return uniform_int_distribution<ll> (l, r)(rng);
}
int n;
vector<int> edges[maxn];
int vt[maxn], used[maxn], a[maxn];
int child[maxn], cnt;
ll ans1, ans2;
void DFS(int u, int par)
{
child[u] = 1, vt[++cnt] = u;
for(int v : edges[u]){
if(v == par) continue;
DFS(v, u);
child[u] += child[v];
if(!used[v]) {
used[u] = 1, swap(a[u], a[v]);
ans2 += 2;
}
}
if(u != 1) ans1 += min(child[u], n - child[u]) * 2;
else if(!used[1]) ans2 += 2, swap(a[1], a[edges[1][0]]);
}
void solve()
{
cin >> n;
fi(i, 1, n - 1) {
int x, y;
cin >> x >> y;
edges[x].push_back(y);
edges[y].push_back(x);
}
fi(i, 1, n) a[i] = i;
DFS(1, 0);
fi(i, n + 1, 2 * n) vt[i] = vt[i - n];
cout << ans2 << " " << ans1 <<'\n';
fi(i, 1, n) cout << a[i] << " ";
cout << '\n';
fi(i, 1, n) cout << vt[i + (n / 2)] << " ";
}
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(VietAnh".inp", "r")) {
freopen(VietAnh".inp", "r", stdin);
freopen(VietAnh".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
Village.cpp: In function 'int main()':
Village.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(VietAnh".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Village.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(VietAnh".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
3 |
Correct |
2 ms |
8028 KB |
Output is correct |
4 |
Correct |
2 ms |
8108 KB |
Output is correct |
5 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
6 |
Partially correct |
2 ms |
8108 KB |
Partially correct |
7 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
8 |
Partially correct |
2 ms |
7840 KB |
Partially correct |
9 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
10 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
11 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
12 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
13 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
14 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
15 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
16 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
17 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
2 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
3 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
4 |
Partially correct |
3 ms |
8112 KB |
Partially correct |
5 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
6 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
7 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
8 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
9 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
10 |
Partially correct |
3 ms |
8108 KB |
Partially correct |
11 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
12 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
13 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
14 |
Partially correct |
2 ms |
8124 KB |
Partially correct |
15 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
16 |
Partially correct |
3 ms |
8284 KB |
Partially correct |
17 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
18 |
Partially correct |
2 ms |
8112 KB |
Partially correct |
19 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
20 |
Partially correct |
2 ms |
8108 KB |
Partially correct |
21 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
22 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
23 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
24 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
25 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
26 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
27 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
28 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
29 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
30 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
3 |
Correct |
2 ms |
8028 KB |
Output is correct |
4 |
Correct |
2 ms |
8108 KB |
Output is correct |
5 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
6 |
Partially correct |
2 ms |
8108 KB |
Partially correct |
7 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
8 |
Partially correct |
2 ms |
7840 KB |
Partially correct |
9 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
10 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
11 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
12 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
13 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
14 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
15 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
16 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
17 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
18 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
19 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
20 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
21 |
Partially correct |
3 ms |
8112 KB |
Partially correct |
22 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
23 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
24 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
25 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
26 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
27 |
Partially correct |
3 ms |
8108 KB |
Partially correct |
28 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
29 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
30 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
31 |
Partially correct |
2 ms |
8124 KB |
Partially correct |
32 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
33 |
Partially correct |
3 ms |
8284 KB |
Partially correct |
34 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
35 |
Partially correct |
2 ms |
8112 KB |
Partially correct |
36 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
37 |
Partially correct |
2 ms |
8108 KB |
Partially correct |
38 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
39 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
40 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
41 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
42 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
43 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
44 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
45 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
46 |
Partially correct |
2 ms |
8028 KB |
Partially correct |
47 |
Partially correct |
2 ms |
8024 KB |
Partially correct |
48 |
Partially correct |
33 ms |
13380 KB |
Partially correct |
49 |
Partially correct |
38 ms |
13648 KB |
Partially correct |
50 |
Partially correct |
37 ms |
13652 KB |
Partially correct |
51 |
Partially correct |
29 ms |
12380 KB |
Partially correct |
52 |
Partially correct |
40 ms |
13648 KB |
Partially correct |
53 |
Partially correct |
39 ms |
13140 KB |
Partially correct |
54 |
Partially correct |
22 ms |
14420 KB |
Partially correct |
55 |
Partially correct |
43 ms |
21072 KB |
Partially correct |
56 |
Partially correct |
39 ms |
17244 KB |
Partially correct |
57 |
Partially correct |
64 ms |
15956 KB |
Partially correct |
58 |
Partially correct |
37 ms |
14932 KB |
Partially correct |
59 |
Partially correct |
36 ms |
13916 KB |
Partially correct |
60 |
Correct |
31 ms |
14036 KB |
Output is correct |
61 |
Partially correct |
32 ms |
14164 KB |
Partially correct |
62 |
Partially correct |
33 ms |
14172 KB |
Partially correct |
63 |
Partially correct |
37 ms |
13904 KB |
Partially correct |
64 |
Partially correct |
34 ms |
14152 KB |
Partially correct |
65 |
Partially correct |
32 ms |
14252 KB |
Partially correct |
66 |
Partially correct |
30 ms |
13892 KB |
Partially correct |
67 |
Partially correct |
25 ms |
12632 KB |
Partially correct |
68 |
Partially correct |
28 ms |
13148 KB |
Partially correct |
69 |
Partially correct |
33 ms |
14172 KB |
Partially correct |
70 |
Partially correct |
30 ms |
14160 KB |
Partially correct |
71 |
Partially correct |
23 ms |
12328 KB |
Partially correct |
72 |
Partially correct |
27 ms |
12892 KB |
Partially correct |
73 |
Partially correct |
31 ms |
14172 KB |
Partially correct |
74 |
Partially correct |
30 ms |
13912 KB |
Partially correct |
75 |
Partially correct |
37 ms |
13652 KB |
Partially correct |
76 |
Partially correct |
39 ms |
13648 KB |
Partially correct |
77 |
Partially correct |
33 ms |
13900 KB |
Partially correct |
78 |
Partially correct |
23 ms |
11868 KB |
Partially correct |
79 |
Partially correct |
26 ms |
12628 KB |
Partially correct |
80 |
Partially correct |
36 ms |
13616 KB |
Partially correct |
81 |
Partially correct |
38 ms |
14136 KB |
Partially correct |
82 |
Partially correct |
32 ms |
13996 KB |
Partially correct |