// luogu-judger-enable-o2
// luogu-judger-enable-o2
#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct Edge{
int to,next;
}e[10005];
int prt[5005],h[5005],cnt=1,n,m,used[5005],fa[5005],inans[5005],sss;
vector<int> a;
vector<int> ans[5005];
void Add_Edge(int x,int y){
e[++cnt].to=y;
e[cnt].next=h[x];
h[x]=cnt;
}
void dfs2(int point){
if(used[point]&&prt[point]){
dfs2(prt[point]);
return ;
}
if(!inans[point])a.push_back(point),inans[point]=1;
vector<int>tmp;
for(int i=h[point];i;i=e[i].next){
int y=e[i].to;
if(!used[y]&&y!=prt[point])tmp.push_back(y);
}
used[point]=1;
sort(tmp.begin(),tmp.end());
for(int i=0;i<tmp.size();i++)dfs2(tmp[i]);
if(!used[prt[point]])dfs2(prt[point]);
used[point]=0;
}
void dfs1(int point,int nx,int ny){
if(used[point])return ;
used[point]=1;
a.push_back(point);
vector<int> vec;
// cout<<"now:"<<point<<endl;
for(int i=h[point];i;i=e[i].next){
int y=e[i].to;
if(!used[y]&&!((point==nx&&y==ny)||(point==ny&&y==nx)))vec.push_back(y);//,cout<<y<<' ';
}
// puts("");
sort(vec.begin(),vec.end());
for(int i=0;i<vec.size();i++)dfs1(vec[i],nx,ny);
}
bool usedb[10005];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
Add_Edge(x,y);
Add_Edge(y,x);
}
if(m==n-1){
used[0]=1;
dfs2(1);
for(int i=0;i<n;i++)cout<<a[i]<<' ';
}
else {
for(int i=1;i<=n;i++){
for(int j=h[i];j;j=e[j].next){
if(usedb[j])continue;
usedb[j]=usedb[j^1]=1;
memset(used,0,sizeof(used));
//cout<<"duanbian:"<<i<<' '<<e[j].to<<endl;
dfs1(1,i,e[j].to);
if(a.size()==n)ans[++sss]=a;
//for(int i=0;i<a.size();i++)cout<<a[i]<<' ';
//cout<<endl;
a.clear();
}
}
sort(ans+1,ans+sss+1);
for(int i=0;i<ans[1].size();i++)cout<<ans[1][i]<<' ';
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 63.8 us | 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 67.95 us | 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 67.42 us | 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 82.16 us | 184 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 81.03 us | 184 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 233.64 us | 324 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 234.17 us | 336 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 232.2 us | 340 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 252.55 us | 284 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 252.36 us | 276 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 1.066 ms | 704 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 1.057 ms | 844 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 1.032 ms | 872 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 1.042 ms | 696 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 1.034 ms | 968 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 72.48 us | 192 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 70.77 us | 192 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 499.27 us | 224 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 468.62 us | 220 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 30.758 ms | 4 MB + 188 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 31.446 ms | 4 MB + 184 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 31.295 ms | 4 MB + 188 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 1 s | 58 MB + 600 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
Testcase #24 | 1 s | 52 MB + 648 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
Testcase #25 | 1 s | 46 MB + 872 KB | Time Limit Exceeded | Score: 0 | 显示更多 |