#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<std::vector<int>> adj(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
std::cin >> u >> v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
int mn = 0;
std::vector<int> w(n, -1);
std::function<void(int, int)> dfs = [&](int u, int p) {
std::vector<int> a;
int x = -1;
for (int v : adj[u]) {
if (v == p)
continue;
dfs(v, u);
if (w[v] == -1) {
a.push_back(v);
}
x = v;
}
int m = a.size();
if (m % 2 == 1) {
for (int i = 0; i < m - 2; i += 2) {
mn += 4;
w[a[i]] = a[i + 1];
w[a[i + 1]] = a[i];
}
mn += 2;
w[u] = a[m - 1];
w[a[m - 1]] = u;
} else {
for (int i = 0; i < m; i += 2) {
mn += 4;
w[a[i]] = a[i + 1];
w[a[i + 1]] = a[i];
}
if (m >= 2) {
w[u] = a[0];
w[a[0]] = a[1];
w[a[1]] = u;
} else if (p == -1) {
mn += 2;
w[u] = w[x];
w[x] = u;
}
}
};
dfs(0, -1);
std::cout << mn << " " << 0 << "\n";
for (int i = 0; i < n; i++) {
std::cout << w[i] + 1 << " \n"[i == n - 1];
}
for (int i = 0; i < n; i++) {
std::cout << 1 << " \n"[i == n - 1];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Partially correct |
2 |
Partially correct |
1 ms |
212 KB |
Partially correct |
3 |
Partially correct |
1 ms |
212 KB |
Partially correct |
4 |
Partially correct |
0 ms |
212 KB |
Partially correct |
5 |
Partially correct |
0 ms |
212 KB |
Partially correct |
6 |
Partially correct |
0 ms |
212 KB |
Partially correct |
7 |
Partially correct |
1 ms |
320 KB |
Partially correct |
8 |
Partially correct |
1 ms |
320 KB |
Partially correct |
9 |
Partially correct |
1 ms |
216 KB |
Partially correct |
10 |
Partially correct |
0 ms |
320 KB |
Partially correct |
11 |
Partially correct |
1 ms |
212 KB |
Partially correct |
12 |
Partially correct |
1 ms |
324 KB |
Partially correct |
13 |
Partially correct |
1 ms |
212 KB |
Partially correct |
14 |
Partially correct |
1 ms |
276 KB |
Partially correct |
15 |
Partially correct |
0 ms |
212 KB |
Partially correct |
16 |
Partially correct |
0 ms |
320 KB |
Partially correct |
17 |
Partially correct |
1 ms |
212 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Partially correct |
2 |
Partially correct |
1 ms |
320 KB |
Partially correct |
3 |
Partially correct |
1 ms |
340 KB |
Partially correct |
4 |
Partially correct |
1 ms |
340 KB |
Partially correct |
5 |
Partially correct |
1 ms |
324 KB |
Partially correct |
6 |
Partially correct |
1 ms |
340 KB |
Partially correct |
7 |
Partially correct |
1 ms |
448 KB |
Partially correct |
8 |
Partially correct |
1 ms |
340 KB |
Partially correct |
9 |
Partially correct |
1 ms |
340 KB |
Partially correct |
10 |
Partially correct |
1 ms |
340 KB |
Partially correct |
11 |
Partially correct |
2 ms |
340 KB |
Partially correct |
12 |
Partially correct |
1 ms |
340 KB |
Partially correct |
13 |
Partially correct |
1 ms |
340 KB |
Partially correct |
14 |
Partially correct |
1 ms |
328 KB |
Partially correct |
15 |
Partially correct |
1 ms |
340 KB |
Partially correct |
16 |
Partially correct |
1 ms |
340 KB |
Partially correct |
17 |
Partially correct |
1 ms |
340 KB |
Partially correct |
18 |
Partially correct |
1 ms |
340 KB |
Partially correct |
19 |
Partially correct |
1 ms |
340 KB |
Partially correct |
20 |
Partially correct |
1 ms |
340 KB |
Partially correct |
21 |
Partially correct |
1 ms |
340 KB |
Partially correct |
22 |
Partially correct |
1 ms |
340 KB |
Partially correct |
23 |
Partially correct |
1 ms |
340 KB |
Partially correct |
24 |
Partially correct |
1 ms |
340 KB |
Partially correct |
25 |
Partially correct |
1 ms |
340 KB |
Partially correct |
26 |
Partially correct |
1 ms |
340 KB |
Partially correct |
27 |
Partially correct |
1 ms |
316 KB |
Partially correct |
28 |
Partially correct |
1 ms |
340 KB |
Partially correct |
29 |
Partially correct |
1 ms |
340 KB |
Partially correct |
30 |
Partially correct |
1 ms |
340 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Partially correct |
2 |
Partially correct |
1 ms |
212 KB |
Partially correct |
3 |
Partially correct |
1 ms |
212 KB |
Partially correct |
4 |
Partially correct |
0 ms |
212 KB |
Partially correct |
5 |
Partially correct |
0 ms |
212 KB |
Partially correct |
6 |
Partially correct |
0 ms |
212 KB |
Partially correct |
7 |
Partially correct |
1 ms |
320 KB |
Partially correct |
8 |
Partially correct |
1 ms |
320 KB |
Partially correct |
9 |
Partially correct |
1 ms |
216 KB |
Partially correct |
10 |
Partially correct |
0 ms |
320 KB |
Partially correct |
11 |
Partially correct |
1 ms |
212 KB |
Partially correct |
12 |
Partially correct |
1 ms |
324 KB |
Partially correct |
13 |
Partially correct |
1 ms |
212 KB |
Partially correct |
14 |
Partially correct |
1 ms |
276 KB |
Partially correct |
15 |
Partially correct |
0 ms |
212 KB |
Partially correct |
16 |
Partially correct |
0 ms |
320 KB |
Partially correct |
17 |
Partially correct |
1 ms |
212 KB |
Partially correct |
18 |
Partially correct |
1 ms |
212 KB |
Partially correct |
19 |
Partially correct |
1 ms |
320 KB |
Partially correct |
20 |
Partially correct |
1 ms |
340 KB |
Partially correct |
21 |
Partially correct |
1 ms |
340 KB |
Partially correct |
22 |
Partially correct |
1 ms |
324 KB |
Partially correct |
23 |
Partially correct |
1 ms |
340 KB |
Partially correct |
24 |
Partially correct |
1 ms |
448 KB |
Partially correct |
25 |
Partially correct |
1 ms |
340 KB |
Partially correct |
26 |
Partially correct |
1 ms |
340 KB |
Partially correct |
27 |
Partially correct |
1 ms |
340 KB |
Partially correct |
28 |
Partially correct |
2 ms |
340 KB |
Partially correct |
29 |
Partially correct |
1 ms |
340 KB |
Partially correct |
30 |
Partially correct |
1 ms |
340 KB |
Partially correct |
31 |
Partially correct |
1 ms |
328 KB |
Partially correct |
32 |
Partially correct |
1 ms |
340 KB |
Partially correct |
33 |
Partially correct |
1 ms |
340 KB |
Partially correct |
34 |
Partially correct |
1 ms |
340 KB |
Partially correct |
35 |
Partially correct |
1 ms |
340 KB |
Partially correct |
36 |
Partially correct |
1 ms |
340 KB |
Partially correct |
37 |
Partially correct |
1 ms |
340 KB |
Partially correct |
38 |
Partially correct |
1 ms |
340 KB |
Partially correct |
39 |
Partially correct |
1 ms |
340 KB |
Partially correct |
40 |
Partially correct |
1 ms |
340 KB |
Partially correct |
41 |
Partially correct |
1 ms |
340 KB |
Partially correct |
42 |
Partially correct |
1 ms |
340 KB |
Partially correct |
43 |
Partially correct |
1 ms |
340 KB |
Partially correct |
44 |
Partially correct |
1 ms |
316 KB |
Partially correct |
45 |
Partially correct |
1 ms |
340 KB |
Partially correct |
46 |
Partially correct |
1 ms |
340 KB |
Partially correct |
47 |
Partially correct |
1 ms |
340 KB |
Partially correct |
48 |
Partially correct |
51 ms |
7520 KB |
Partially correct |
49 |
Partially correct |
52 ms |
8268 KB |
Partially correct |
50 |
Partially correct |
50 ms |
8260 KB |
Partially correct |
51 |
Partially correct |
47 ms |
6408 KB |
Partially correct |
52 |
Partially correct |
56 ms |
8100 KB |
Partially correct |
53 |
Partially correct |
45 ms |
7364 KB |
Partially correct |
54 |
Partially correct |
28 ms |
9804 KB |
Partially correct |
55 |
Partially correct |
64 ms |
20180 KB |
Partially correct |
56 |
Partially correct |
75 ms |
14028 KB |
Partially correct |
57 |
Partially correct |
60 ms |
12052 KB |
Partially correct |
58 |
Partially correct |
72 ms |
10292 KB |
Partially correct |
59 |
Partially correct |
51 ms |
8304 KB |
Partially correct |
60 |
Partially correct |
41 ms |
8512 KB |
Partially correct |
61 |
Partially correct |
46 ms |
8704 KB |
Partially correct |
62 |
Partially correct |
49 ms |
8744 KB |
Partially correct |
63 |
Partially correct |
41 ms |
8120 KB |
Partially correct |
64 |
Partially correct |
71 ms |
8532 KB |
Partially correct |
65 |
Partially correct |
46 ms |
8780 KB |
Partially correct |
66 |
Partially correct |
49 ms |
8140 KB |
Partially correct |
67 |
Partially correct |
32 ms |
6524 KB |
Partially correct |
68 |
Partially correct |
36 ms |
7372 KB |
Partially correct |
69 |
Partially correct |
41 ms |
8640 KB |
Partially correct |
70 |
Partially correct |
42 ms |
8140 KB |
Partially correct |
71 |
Partially correct |
61 ms |
6044 KB |
Partially correct |
72 |
Partially correct |
33 ms |
6928 KB |
Partially correct |
73 |
Partially correct |
41 ms |
8720 KB |
Partially correct |
74 |
Partially correct |
41 ms |
7960 KB |
Partially correct |
75 |
Partially correct |
49 ms |
8124 KB |
Partially correct |
76 |
Partially correct |
50 ms |
8128 KB |
Partially correct |
77 |
Partially correct |
44 ms |
8172 KB |
Partially correct |
78 |
Partially correct |
33 ms |
5560 KB |
Partially correct |
79 |
Partially correct |
35 ms |
6476 KB |
Partially correct |
80 |
Partially correct |
49 ms |
8048 KB |
Partially correct |
81 |
Partially correct |
46 ms |
8264 KB |
Partially correct |
82 |
Partially correct |
59 ms |
8436 KB |
Partially correct |