#include <bits/stdc++.h>
#define ff first
#define ss second
#define sz size()
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 15;
const int INF = 1e9;
void solve();
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
// indexed_set s;
int cost[N][N], mn, mx, sum;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> n;
vector <int> a(n, 0), jog1(n, 0), jog2(n, 0);
for (int i = 0; i < n; ++i) {
a[i] = i;
for (int j = 0; j < n; ++j) {
if (i == j) continue;
cost[i][j] = INF;
}
}
for (int i = 1; i <= n; ++i) {
int l, r;
cin >> l >> r;
l--;
r--;
cost[l][r] = 1;
cost[r][l] = 1;
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cost[i][j] = min (cost[i][j], cost[i][k] + cost[k][j]);
}
}
}
mn = INF;
mx = 0;
do {
sum = 0;
bool tr = 0;
for (int i = 0; i < n; ++i) {
if (i == a[i]) tr = 1;
sum += cost[i][a[i]];
}
if (tr) continue;
if (mn > sum) {
jog1 = a;
mn = sum;
}
if (mx < sum) {
jog2 = a;
mx = sum;
}
}while (next_permutation(a.begin(), a.end()));
cout << mn << ' ' << mx << '\n';
for (int i : jog1) cout << i + 1 << ' ';
cout << '\n';
for (int i : jog2) cout << i + 1 << ' ';
}
/*
.-~~~~~~~~~-._ _.-~~~~~~~~~-.
__.' ~. .~ `.__
.'// \./ \`.
.'// | \`.
.'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \`.
.'//.-" `-. | .-' "-.\`.
.'//______.============-.. \ | / ..-============.______\`.
.'______________________________\|/______________________________`.
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
5 ms |
212 KB |
Output is correct |
10 |
Correct |
51 ms |
212 KB |
Output is correct |
11 |
Correct |
52 ms |
212 KB |
Output is correct |
12 |
Correct |
52 ms |
212 KB |
Output is correct |
13 |
Correct |
52 ms |
300 KB |
Output is correct |
14 |
Correct |
56 ms |
292 KB |
Output is correct |
15 |
Correct |
52 ms |
212 KB |
Output is correct |
16 |
Correct |
56 ms |
296 KB |
Output is correct |
17 |
Correct |
51 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
5 ms |
212 KB |
Output is correct |
10 |
Correct |
51 ms |
212 KB |
Output is correct |
11 |
Correct |
52 ms |
212 KB |
Output is correct |
12 |
Correct |
52 ms |
212 KB |
Output is correct |
13 |
Correct |
52 ms |
300 KB |
Output is correct |
14 |
Correct |
56 ms |
292 KB |
Output is correct |
15 |
Correct |
52 ms |
212 KB |
Output is correct |
16 |
Correct |
56 ms |
296 KB |
Output is correct |
17 |
Correct |
51 ms |
296 KB |
Output is correct |
18 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |