// luogu-judger-enable-o2
# include<iostream>
# include<cstring>
# include<cstdio>
# include<vector>
# include<algorithm>
using namespace std;
const int MAX=1e4+5;
struct p{
int x;
bool operator< (const p &a)
const{
return x<a.x;
}
};
struct q{
int x,y;
}s[MAX];
int n,m,num,tot,s1,s2;
int h[MAX],ans[MAX],qu[MAX],Ans[MAX];
vector<p> c[MAX];
bool use[MAX];
bool look(int x,int y)
{
if(s1==x&&s2==y) return 1;
if(s1==y&&s2==x) return 1;
return 0;
}
void Change()
{
for(int i=1;i<=n;++i)
if(Ans[i]&&Ans[i]<ans[i]) return;
else if((Ans[i]&&Ans[i]>ans[i])||!Ans[i])
{
for(int j=1;j<=n;++j)
Ans[j]=ans[j];
return;
}
}
void dfs(int x,int fa)
{
int siz=c[x].size();
use[x]=1,ans[++tot]=x;
for(int i=0;i<siz;++i)
if(c[x][i].x!=fa&&!use[c[x][i].x]&&!look(x,c[x][i].x)) dfs(c[x][i].x,x);
}
int main()
{
// freopen("travel.in","r",stdin);
// freopen("travel.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1,x,y;i<=m;++i)
scanf("%d%d",&x,&y),c[x].push_back((p){y}),c[y].push_back((p){x}),s[i].x=x,s[i].y=y;
for(int i=1;i<=n;++i)
sort(c[i].begin(),c[i].end());
if(m==n-1)
{
dfs(1,0);
for(int i=1;i<=n;++i)
printf("%d ",ans[i]);
}
else
{
for(int i=1;i<=m;++i)
{
memset(use,0,sizeof(use));
s1=s[i].x,s2=s[i].y,tot=0;
dfs(1,0);
if(tot==n) Change();
}
for(int i=1;i<=n;++i)
printf("%d ",Ans[i]);
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 71.4 us | 288 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 77.31 us | 288 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 70.6 us | 288 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 96.77 us | 296 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 96.76 us | 296 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 355.79 us | 376 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 355.4 us | 380 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 356.95 us | 384 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 361.51 us | 364 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 360.9 us | 356 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 1.624 ms | 668 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 1.614 ms | 720 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 1.609 ms | 736 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 1.607 ms | 668 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 1.614 ms | 772 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 73.37 us | 292 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 74.73 us | 292 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 167.83 us | 304 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 170.78 us | 300 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 11.467 ms | 400 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 11.563 ms | 400 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 11.819 ms | 400 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 537.557 ms | 768 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 535.377 ms | 752 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 536.448 ms | 740 KB | Accepted | Score: 4 | 显示更多 |