#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+4;
vector<int> adj[N];
int dfs(int s, int p, int f, int cnt){
if(s==f)return cnt;
for(auto e: adj[s]){
if(e==p)continue;
int r=dfs(e, s, f, cnt+1);
if(r>0)return r;
}return 0;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
vector<int> a;
for(int i=1; i<n; i++){
a.push_back(i);
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}a.push_back(n);
vector<int> small(n+1), largest(n+1);
int mn=1e9, mx=0;
do{
bool check=true;
for(int i=0; i<n; i++){
if(a[i]==i+1)check=false;
}if(check){
int sum=0;
for(int i=0; i<n; i++){
sum+=dfs(a[i], a[i], i+1, 0);
}if(sum>mx){
mx=sum;
for(int i=0; i<n; i++){
largest[i]=a[i];
}
}if(sum<mn){
mn=sum;
for(int i=0; i<n; i++){
small[i]=a[i];
}
}
}
}while(next_permutation(a.begin(), a.end()));
cout<<mn<<" "<<mx<<endl;
for(int j=0; j<n; j++){
cout<<small[j]<<" ";
}cout<<endl;
for(int j=0; j<n; j++){
cout<<largest[j]<<" ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |