#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
#define free freeee
#define lcm llcm
/*
⠄⠄⠄⠄⢠⣿⣿⣿⣿⣿⢻⣿⣿⣿⣿⣿⣿⣿⣿⣯⢻⣿⣿⣿⣿⣆⠄⠄⠄
⠄⠄⣼⢀⣿⣿⣿⣿⣏⡏⠄⠹⣿⣿⣿⣿⣿⣿⣿⣿⣧⢻⣿⣿⣿⣿⡆⠄⠄
⠄⠄⡟⣼⣿⣿⣿⣿⣿⠄⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⣿⣇⢻⣿⣿⣿⣿⠄⠄
⠄⢰⠃⣿⣿⠿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠙⠿⣿⣿⣿⣿⣿⠄⢿⣿⣿⣿⡄⠄
⠄⢸⢠⣿⣿⣧⡙⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠈⠛⢿⣿⣿⡇⠸⣿⡿⣸⡇⠄
⠄⠈⡆⣿⣿⣿⣿⣦⡙⠳⠄⠄⠄⠄⠄⠄⢀⣠⣤⣀⣈⠙⠃⠄⠿⢇⣿⡇⠄
⠄⠄⡇⢿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⣠⣶⣿⣿⣿⣿⣿⣿⣷⣆⡀⣼⣿⡇⠄
⠄⠄⢹⡘⣿⣿⣿⢿⣷⡀⠄⢀⣴⣾⣟⠉⠉⠉⠉⣽⣿⣿⣿⣿⠇⢹⣿⠃⠄
⠄⠄⠄⢷⡘⢿⣿⣎⢻⣷⠰⣿⣿⣿⣿⣦⣀⣀⣴⣿⣿⣿⠟⢫⡾⢸⡟⠄.
⠄⠄⠄⠄⠻⣦⡙⠿⣧⠙⢷⠙⠻⠿⢿⡿⠿⠿⠛⠋⠉⠄⠂⠘⠁⠞⠄⠄⠄
⠄⠄⠄⠄⠄⠈⠙⠑⣠⣤⣴⡖⠄⠿⣋⣉⣉⡁⠄⢾⣦⠄⠄⠄⠄⠄⠄⠄⠄
*/
typedef unsigned long long ull;
using namespace std;
const int N=1e3+5;
int dis[N][N],n;
vector<int> adj[N];
void dfs(int x,int p,int s,int d){
dis[s][x]=d;
for (auto u:adj[x]) if (u!=p) dfs(u,x,s,d+1);
return;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=1;i<n;i++){
int x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
for (int i=1;i<=n;i++) dfs(i,0,i,0);
int mn=LLONG_MAX,mx=LLONG_MIN;
vector<int> v1,v2,v;
for (int i=1;i<=n;i++) v.pb(i);
do{
bool ok=true;
for (int i=0;i<v.size();i++) ok&=(v[i]!=i+1);
if (!ok) continue;
int c=0;
for (int i=0;i<v.size();i++) c+=dis[i+1][v[i]];
if (c<mn){
mn=c;
v1=v;
}
if (c>mx){
mx=c;
v2=v;
}
}while(next_permutation(v.begin(),v.end()));
cout<<mn<<' '<<mx<<endl;
for (auto u:v1) cout<<u<<' ';cout<<endl;
for (auto u:v2) cout<<u<<' ';cout<<endl;
return 0;
}
Compilation message
Village.cpp: In function 'int32_t main()':
Village.cpp:55:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i=0;i<v.size();i++) ok&=(v[i]!=i+1);
| ~^~~~~~~~~
Village.cpp:58:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i=0;i<v.size();i++) c+=dis[i+1][v[i]];
| ~^~~~~~~~~
Village.cpp:69:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
69 | for (auto u:v1) cout<<u<<' ';cout<<endl;
| ^~~
Village.cpp:69:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
69 | for (auto u:v1) cout<<u<<' ';cout<<endl;
| ^~~~
Village.cpp:70:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
70 | for (auto u:v2) cout<<u<<' ';cout<<endl;
| ^~~
Village.cpp:70:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
70 | for (auto u:v2) cout<<u<<' ';cout<<endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
61 ms |
596 KB |
Output is correct |
11 |
Correct |
54 ms |
344 KB |
Output is correct |
12 |
Correct |
58 ms |
512 KB |
Output is correct |
13 |
Correct |
55 ms |
344 KB |
Output is correct |
14 |
Correct |
54 ms |
348 KB |
Output is correct |
15 |
Correct |
58 ms |
516 KB |
Output is correct |
16 |
Correct |
57 ms |
348 KB |
Output is correct |
17 |
Correct |
54 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1014 ms |
2652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
61 ms |
596 KB |
Output is correct |
11 |
Correct |
54 ms |
344 KB |
Output is correct |
12 |
Correct |
58 ms |
512 KB |
Output is correct |
13 |
Correct |
55 ms |
344 KB |
Output is correct |
14 |
Correct |
54 ms |
348 KB |
Output is correct |
15 |
Correct |
58 ms |
516 KB |
Output is correct |
16 |
Correct |
57 ms |
348 KB |
Output is correct |
17 |
Correct |
54 ms |
348 KB |
Output is correct |
18 |
Execution timed out |
1014 ms |
2652 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |