#include<iostream> #define MAX 1002 using namespace std; int g[MAX][MAX]; int been[MAX]; int n,m,s; bool DFS(int start); int re[MAX]; int index = 0; int max_num = 0; int main() { int a,b; cin>>n>>m>>s; re[index++] = s; for(int i = 0;i < m; i++) { cin>>a>>b; if(a>max_num) max_num = a; if(b>max_num) max_num = b; g[a][b]=g[b][a]=1; } cout<<s; if(DFS(s)) { //cout<<"susses!"; //cout<<index<<endl; index = index-2; while(index>=0) cout<<' '<<re[index--]; } else { //cout<<n<<endl; for(int i = 1 ;i<=n;i++) if(been[i]) cout<<' '<<i; cout<<' '<<0; } return 0; } bool DFS(int start) { int s = start , cnt = 1,i; been[s] = 1; while(cnt!=n) { int temp = s; int sign_this = 0; for(i =1;i <= max_num;i++) { if(g[s][i]&&(!been[i])&(i!=s)) { cout<<" "<<i; re[index++] = i; g[s][i]=g[i][s]=0; been[i] = 1; s = i; cnt++; i = 1; } } if(s==temp) { been[s] = 0; return false; break; } } return true; }