#include <bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(0), cin.tie(0);
using namespace std;
const int MAX_N = 10+10;
const int INF = 2e18;
int n;
int a, b;
vector<vector<int>> G(MAX_N);
vector<vector<int>> dis(MAX_N, vector<int>(MAX_N));
void dfs(int start, int now, int pre){
if (pre!=-1) dis[start][now] = dis[start][pre]+1;
for (auto x : G[now]){
if (x!=pre){
dfs(start, x, now);
}
}
return;
}
void solve1(){
// input
cin >> n;
for (int i=0 ; i<n-1 ; i++){
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
// init
vector<int> v;
for (int i=0 ; i<n ; i++){
v.push_back(i);
dfs(i, i, -1);
}
// for (int i=0 ; i<n ; i++){
// for (int j=0 ; j<n ; j++){
// cerr << dis[i][j] << " ";
// }
// cerr << "\n";
// }
// return;
// process
int ma = -INF, mi = INF;
vector<int> ma_ans, mi_ans;
do{
int total = 0;
for (int i=0 ; i<n ; i++){
if (i==v[i]) goto flag;
total += dis[i][v[i]];
}
if (total>ma){
ma = total;
ma_ans = v;
}
if (total<mi){
mi = total;
mi_ans = v;
}
flag:;
} while (next_permutation(v.begin(), v.end()));
cout << mi << " " << ma << "\n";
for (auto x : mi_ans){
cout << x+1 << " ";
}
cout << "\n";
for (auto x : ma_ans){
cout << x+1 << " ";
}
cout << "\n";
return;
}
signed main(){
fastio;
int t = 1;
while (t--){
solve1();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
36 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
344 KB |
Output is correct |
12 |
Correct |
36 ms |
348 KB |
Output is correct |
13 |
Correct |
37 ms |
344 KB |
Output is correct |
14 |
Correct |
36 ms |
500 KB |
Output is correct |
15 |
Correct |
35 ms |
348 KB |
Output is correct |
16 |
Correct |
39 ms |
348 KB |
Output is correct |
17 |
Correct |
36 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
36 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
344 KB |
Output is correct |
12 |
Correct |
36 ms |
348 KB |
Output is correct |
13 |
Correct |
37 ms |
344 KB |
Output is correct |
14 |
Correct |
36 ms |
500 KB |
Output is correct |
15 |
Correct |
35 ms |
348 KB |
Output is correct |
16 |
Correct |
39 ms |
348 KB |
Output is correct |
17 |
Correct |
36 ms |
344 KB |
Output is correct |
18 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 6 |
19 |
Halted |
0 ms |
0 KB |
- |