#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 5500
struct gg{
int to,from,next;
}side[2*maxn];
int n,m,on[maxn],head[maxn],dfn[maxn],tot;
bool use=0;
int cnt=0;
void insert(int u,int v){
struct gg a={v,u,head[u]};side[++cnt]=a;head[u]=cnt;return;
}
bool visit[maxn],pre[maxn];
bool cir(int now,int fa){
pre[now]=1;
for(int i=head[now];i;i=side[i].next){
int u=side[i].to;
if(u==fa)continue;
if(pre[u]){
on[u]=1;on[now]=1;return 1;
}
if(cir(u,now)){
if(on[now]){
return 0;
}
else{
on[now]=1;return 1;
}
}
}
return 0;
}
void dfs(int now,int mem){
if(visit[now])return;
visit[now]=1;
dfn[++tot]=now;
int data[maxn],tg=0;
for(int i=head[now];i;i=side[i].next){
int u=side[i].to;
if(visit[u])continue;
data[++tg]=u;
}
//cout<<data[1]<<endl;
if(!tg)return;
sort(data+1,data+1+tg);
for(int i=1;i<=tg;i++){
if(visit[data[i]])continue;
if(data[i]>mem&&mem&&!use){
use=1;return;
}
if(on[now]&&on[data[i]]&&i!=tg){
dfs(data[i],data[i+1]);
}
else if(tg==i){
dfs(data[i],mem);
}
else{
dfs(data[i],0);
}
}
return;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int u,v;scanf("%d%d",&u,&v);
insert(u,v);insert(v,u);
}
if(n==m){
use=0;
cir(1,0);
use=0;dfs(1,0);
}
else{
use=1;
dfs(1,0);
}
for(int i=1;i<=tot;i++){
printf("%d ",dfn[i]);
}
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 42.45 us | 140 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 50.6 us | 144 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 131.44 us | 1 MB + 84 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 138.13 us | 1 MB + 300 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 5.038 ms | 59 MB + 448 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 4.645 ms | 53 MB + 488 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 219.16 us | 400 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #8 | 231.66 us | 404 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #9 | 686.18 us | 1 MB + 944 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #10 | 712.49 us | 1 MB + 944 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #11 | 267.75 us | 988 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #12 | 326.57 us | 1 MB + 364 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #13 | 5.303 ms | 62 MB + 972 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 6.554 ms | 82 MB + 28 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 241.92 us | 404 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #16 | 221.29 us | 396 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #17 | 474.9 us | 1 MB + 940 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 488.73 us | 1 MB + 924 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 891.78 us | 1 MB + 944 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 330.09 us | 1 MB + 396 KB | Runtime Error | Score: 0 | 显示更多 |