#include <fstream>using namespace std;ifstream fin("BFS.in");ofstream fout("BFS.out");int n,m,a[101][101],k;void bf(int x){ int c[101],viz[101]={0},p,u,z,i; p=u=1; c[p]=x; viz[x]=1; while(p<=u) { z=c[p]; for(i=1;i<=n;i++) if(a[z][i]==1 && viz[i]==0) { u++;c[u]=i;viz[i]=1; } p++; } for(i=1;i<=u;i++) fout<<c[i]<<' ';}int main(){ int i,x,y; fin>>n>>m; fin>>k; for(i=1;i<=m;i++) { fin>>x>>y; a[x][y]=1;a[y][x]=1; }
bf(k); return 0;}