#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 200007;
const ll M = 307;
const ll LG = 31;
ll n, m, k;
vector<int>g[N];
vector<int>res_mn;
ll ans_mn = 0;
bool used[N];
void dfs(int v, int par = -1) {
for (int to : g[v]) {
if (to != par) {
dfs(to, v);
}
}
vector<int>leaves;
for (int to : g[v]) {
if (to != par) {
if (!used[to]) {
leaves.push_back(to);
}
}
}
if (leaves.size() != 0) {
ans_mn += leaves.size() * 2;
res_mn[v] = leaves[0];
for (int i = 0; i < leaves.size() - 1; i++) {
res_mn[leaves[i]] = leaves[i + 1];
}
res_mn[leaves[leaves.size() - 1]] = v;
for (int to : leaves) {
used[to] = true;
}
used[v] = true;
}
}
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
int leaf = 0;
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int v = 1; v <= n; v++) {
if (g[v].size() == 1) {
leaf = v;
break;
}
}
int root = g[leaf][0];
res_mn.resize(n + 1, 0);
dfs(root);
cout << ans_mn << " ";
cout << ans_mn << endl;
for (int v = 1; v <= n; v++) {
cout << res_mn[v] << " ";
}
cout << endl;
for (int v = 1; v <= n; v++) {
cout << res_mn[v] << " ";
}
cout << endl;
}
/// ---- - -------- ------ -------- -- - - -
/// Just a reminder. Ubuntu password is I O I
/// ---- - -------- ------ -------- -- - - -
Compilation message
Village.cpp: In function 'void dfs(int, int)':
Village.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < leaves.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
2 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
3 |
Correct |
3 ms |
4924 KB |
Output is correct |
4 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
5 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
6 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
9 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
10 |
Partially correct |
3 ms |
5020 KB |
Partially correct |
11 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
12 |
Partially correct |
4 ms |
4948 KB |
Partially correct |
13 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
16 |
Partially correct |
4 ms |
4948 KB |
Partially correct |
17 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
5028 KB |
Partially correct |
2 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
3 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
4 |
Partially correct |
5 ms |
5028 KB |
Partially correct |
5 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
6 |
Partially correct |
4 ms |
5028 KB |
Partially correct |
7 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
8 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
9 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
10 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
11 |
Partially correct |
5 ms |
5076 KB |
Partially correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
14 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
15 |
Partially correct |
3 ms |
5028 KB |
Partially correct |
16 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
17 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
18 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
19 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
20 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
21 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
22 |
Partially correct |
4 ms |
5028 KB |
Partially correct |
23 |
Partially correct |
5 ms |
5020 KB |
Partially correct |
24 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
25 |
Partially correct |
3 ms |
5028 KB |
Partially correct |
26 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
27 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
28 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
29 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
30 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
2 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
3 |
Correct |
3 ms |
4924 KB |
Output is correct |
4 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
5 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
6 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
9 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
10 |
Partially correct |
3 ms |
5020 KB |
Partially correct |
11 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
12 |
Partially correct |
4 ms |
4948 KB |
Partially correct |
13 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
16 |
Partially correct |
4 ms |
4948 KB |
Partially correct |
17 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
18 |
Partially correct |
3 ms |
5028 KB |
Partially correct |
19 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
20 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
21 |
Partially correct |
5 ms |
5028 KB |
Partially correct |
22 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
23 |
Partially correct |
4 ms |
5028 KB |
Partially correct |
24 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
25 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
26 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
27 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
28 |
Partially correct |
5 ms |
5076 KB |
Partially correct |
29 |
Correct |
3 ms |
5068 KB |
Output is correct |
30 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
31 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
32 |
Partially correct |
3 ms |
5028 KB |
Partially correct |
33 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
34 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
35 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
36 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
37 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
38 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
39 |
Partially correct |
4 ms |
5028 KB |
Partially correct |
40 |
Partially correct |
5 ms |
5020 KB |
Partially correct |
41 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
42 |
Partially correct |
3 ms |
5028 KB |
Partially correct |
43 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
44 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
45 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
46 |
Partially correct |
3 ms |
5024 KB |
Partially correct |
47 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
48 |
Partially correct |
63 ms |
10524 KB |
Partially correct |
49 |
Partially correct |
62 ms |
11056 KB |
Partially correct |
50 |
Partially correct |
65 ms |
11056 KB |
Partially correct |
51 |
Partially correct |
56 ms |
9732 KB |
Partially correct |
52 |
Partially correct |
66 ms |
11040 KB |
Partially correct |
53 |
Partially correct |
70 ms |
10416 KB |
Partially correct |
54 |
Partially correct |
32 ms |
13384 KB |
Partially correct |
55 |
Partially correct |
78 ms |
21836 KB |
Partially correct |
56 |
Partially correct |
81 ms |
16032 KB |
Partially correct |
57 |
Partially correct |
85 ms |
13316 KB |
Partially correct |
58 |
Partially correct |
68 ms |
12684 KB |
Partially correct |
59 |
Partially correct |
67 ms |
11224 KB |
Partially correct |
60 |
Correct |
62 ms |
11292 KB |
Output is correct |
61 |
Partially correct |
66 ms |
11536 KB |
Partially correct |
62 |
Partially correct |
57 ms |
11508 KB |
Partially correct |
63 |
Partially correct |
50 ms |
11084 KB |
Partially correct |
64 |
Partially correct |
71 ms |
11408 KB |
Partially correct |
65 |
Partially correct |
54 ms |
11468 KB |
Partially correct |
66 |
Partially correct |
60 ms |
11040 KB |
Partially correct |
67 |
Partially correct |
42 ms |
9848 KB |
Partially correct |
68 |
Partially correct |
47 ms |
10440 KB |
Partially correct |
69 |
Partially correct |
71 ms |
11492 KB |
Partially correct |
70 |
Partially correct |
53 ms |
11084 KB |
Partially correct |
71 |
Partially correct |
50 ms |
9508 KB |
Partially correct |
72 |
Partially correct |
45 ms |
10084 KB |
Partially correct |
73 |
Partially correct |
52 ms |
11484 KB |
Partially correct |
74 |
Partially correct |
67 ms |
10888 KB |
Partially correct |
75 |
Partially correct |
72 ms |
10956 KB |
Partially correct |
76 |
Partially correct |
55 ms |
10864 KB |
Partially correct |
77 |
Partially correct |
61 ms |
11100 KB |
Partially correct |
78 |
Partially correct |
37 ms |
9096 KB |
Partially correct |
79 |
Partially correct |
44 ms |
9804 KB |
Partially correct |
80 |
Partially correct |
80 ms |
10932 KB |
Partially correct |
81 |
Partially correct |
61 ms |
11276 KB |
Partially correct |
82 |
Partially correct |
53 ms |
11340 KB |
Partially correct |