#include<bits/stdc++.h>usingnamespace std;#defineMAXN1001int path[MAXN][MAXN]={
{
0}};int book[MAXN]={
0};int n, m, s;voiddfs(int u)// u为当前顶点{
book[u]=1;// 走过了ucout << u <<' ';for(int i =1; i <= n; i++){
if(path[u][i]&&!book[i])// u,i之间有路且i没被走过{
dfs(i);cout << u <<' ';}}}// dfsintmain(){
cin >> n >> m >> s;for(int i =0; i < m; i++){
int x, y; cin >> x >> y;// 无向图path[x][y]=1;path[y][x]=1;}dfs(s);int flag =1;for(int i =1; i <= n; i++){
if(!book[i])// 还有没被走过的顶点{
flag =0;break;}}if(!flag) cout <<0;cout << endl;return0;}