#include <fstream>
#include <vector>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
struct muchie
{
int i,j;
};
vector<int> V[50];//listele de adiacenta
int n,m;//noduri/muchii
int s; //vf de pornire
int p[50];//vizitat/nevizitat
void citire()
{
int x,y,i;
fin>>n>>m;
for(i=1;i<=m;i++)
{
fin>>x>>y;
V[x].insert(V[x].end(),y); //V[x].push_back(y);
V[y].insert(V[y].end(),x); //V[y].push_back(x);
}
fin>>s;
}
void DF(int k)
{
fout<<k<<" ";
p[k]=1;
for(int i=0;i<V[k].size();i++)
if(!p[V[k][i]])
DF(V[k][i]);
}
int main()
{
citire();
DF(s);
fin.close();
fout.close();
return 0;
}
|