#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <numeric>
using namespace std;
const int MAXN = 1e5 + 123;
vector<int> edg[MAXN];
bitset<MAXN> used;
int rt[MAXN];
bool dfs_getmark(int v, bitset<MAXN>& mark) {
bool is_edge = false;
for (auto u : edg[v]) {
if (u == rt[v])
continue;
rt[u] = v;
is_edge |= dfs_getmark(u, mark);
}
if (v == 0) {
mark[v] = 1;
if (is_edge)
return true;
for (auto u : edg[v]) {
if (u == rt[v])
continue;
mark[u] = 0;
return true;
}
}
if (is_edge)
mark[v] = 1;
return !is_edge;
}
void dfs_onmark(int v, bitset<MAXN>& mark, vector<int>& ans) {
ans.push_back(v);
for (auto u : edg[v]) {
if (u == rt[v] || mark[u])
continue;
dfs_onmark(u, mark, ans);
}
}
pair<int, vector<int>> solve_min(int n) {
used = 0;
bitset<MAXN> mark;
dfs_getmark(0, mark);
vector<int> ans(n);
for (int i = 0; i < n; i = mark._Find_next(i)) {
vector<int> ccl;
dfs_onmark(i, mark, ccl);
int m = ccl.size();
for (int j = 0; j < m; ++j) {
ans[ccl[j]] = ccl[(j + 1) % m];
}
}
return {2 * (n - mark.count()), ans};
}
pair<int, vector<int>> solve_max(int n) {
vector<int> pmt(n);
iota(pmt.begin(), pmt.end(), 0);
return {1, pmt};
vector<int> cpmt = pmt;
do {
next_permutation(pmt.begin(), pmt.end());
} while (pmt != cpmt);
}
signed main() {
int n;
cin >> n;
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
edg[u].push_back(v);
edg[v].push_back(u);
}
auto ansmn = solve_min(n);
auto ansmx = solve_max(n);
cout << ansmn.first << ' ' << ansmx.first << '\n';
for (auto x : ansmn.second)
cout << x + 1 << ' ';
cout << '\n';
for (auto x : ansmx.second)
cout << x + 1 << ' ';
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2644 KB |
Partially correct |
4 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
5 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
6 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
7 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
8 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
9 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
10 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
11 |
Partially correct |
1 ms |
2664 KB |
Partially correct |
12 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
13 |
Partially correct |
2 ms |
2656 KB |
Partially correct |
14 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
15 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
16 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
17 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
2 |
Partially correct |
4 ms |
2644 KB |
Partially correct |
3 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
4 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
5 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
6 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
7 |
Partially correct |
2 ms |
2664 KB |
Partially correct |
8 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
9 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
10 |
Partially correct |
2 ms |
2664 KB |
Partially correct |
11 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
12 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
13 |
Partially correct |
4 ms |
2664 KB |
Partially correct |
14 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
15 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
16 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
17 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
18 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
19 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
20 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
21 |
Partially correct |
2 ms |
2672 KB |
Partially correct |
22 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
23 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
24 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
25 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
26 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
27 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
28 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
29 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
30 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2644 KB |
Partially correct |
4 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
5 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
6 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
7 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
8 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
9 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
10 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
11 |
Partially correct |
1 ms |
2664 KB |
Partially correct |
12 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
13 |
Partially correct |
2 ms |
2656 KB |
Partially correct |
14 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
15 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
16 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
17 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
18 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
19 |
Partially correct |
4 ms |
2644 KB |
Partially correct |
20 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
21 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
22 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
23 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
24 |
Partially correct |
2 ms |
2664 KB |
Partially correct |
25 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
26 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
27 |
Partially correct |
2 ms |
2664 KB |
Partially correct |
28 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
29 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
30 |
Partially correct |
4 ms |
2664 KB |
Partially correct |
31 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
32 |
Partially correct |
3 ms |
2664 KB |
Partially correct |
33 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
34 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
35 |
Partially correct |
2 ms |
2660 KB |
Partially correct |
36 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
37 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
38 |
Partially correct |
2 ms |
2672 KB |
Partially correct |
39 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
40 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
41 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
42 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
43 |
Partially correct |
3 ms |
2644 KB |
Partially correct |
44 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
45 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
46 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
47 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
48 |
Partially correct |
97 ms |
9100 KB |
Partially correct |
49 |
Partially correct |
100 ms |
9788 KB |
Partially correct |
50 |
Partially correct |
96 ms |
9796 KB |
Partially correct |
51 |
Partially correct |
127 ms |
8224 KB |
Partially correct |
52 |
Partially correct |
110 ms |
9628 KB |
Partially correct |
53 |
Partially correct |
122 ms |
8944 KB |
Partially correct |
54 |
Partially correct |
50 ms |
9568 KB |
Partially correct |
55 |
Partially correct |
126 ms |
17004 KB |
Partially correct |
56 |
Partially correct |
141 ms |
13324 KB |
Partially correct |
57 |
Partially correct |
109 ms |
12096 KB |
Partially correct |
58 |
Partially correct |
122 ms |
10976 KB |
Partially correct |
59 |
Partially correct |
103 ms |
9328 KB |
Partially correct |
60 |
Partially correct |
112 ms |
9912 KB |
Partially correct |
61 |
Partially correct |
88 ms |
10172 KB |
Partially correct |
62 |
Partially correct |
88 ms |
10124 KB |
Partially correct |
63 |
Partially correct |
101 ms |
9656 KB |
Partially correct |
64 |
Partially correct |
102 ms |
10124 KB |
Partially correct |
65 |
Partially correct |
106 ms |
10208 KB |
Partially correct |
66 |
Partially correct |
88 ms |
9744 KB |
Partially correct |
67 |
Partially correct |
64 ms |
8084 KB |
Partially correct |
68 |
Partially correct |
90 ms |
9036 KB |
Partially correct |
69 |
Partially correct |
87 ms |
10144 KB |
Partially correct |
70 |
Partially correct |
90 ms |
9692 KB |
Partially correct |
71 |
Partially correct |
70 ms |
7892 KB |
Partially correct |
72 |
Partially correct |
72 ms |
8560 KB |
Partially correct |
73 |
Partially correct |
124 ms |
10204 KB |
Partially correct |
74 |
Partially correct |
82 ms |
9572 KB |
Partially correct |
75 |
Partially correct |
104 ms |
9640 KB |
Partially correct |
76 |
Partially correct |
111 ms |
9640 KB |
Partially correct |
77 |
Partially correct |
94 ms |
9872 KB |
Partially correct |
78 |
Partially correct |
68 ms |
7484 KB |
Partially correct |
79 |
Partially correct |
76 ms |
8264 KB |
Partially correct |
80 |
Partially correct |
119 ms |
9672 KB |
Partially correct |
81 |
Partially correct |
100 ms |
9908 KB |
Partially correct |
82 |
Partially correct |
93 ms |
9928 KB |
Partially correct |