Pagini recente » Cod sursa (job #863464) | Cod sursa (job #587426) | Cod sursa (job #548464) | Cod sursa (job #1177975) | Cod sursa (job #2050749)
#include <fstream>
#include <algorithm>
#include <vector>
#define mxvf 100002
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout("sortaret.out");
bool viz[mxvf];
int i,z,nvf,nmc,crt,x,y;
int afis[mxvf],sol;
vector <int> tab[mxvf];
void dfs(int nod)
{
viz[nod]=1;
//afis[++z]=nod;
fout<<nod<<' ';
vector <int>::iterator it;
for ( it=tab[nod].begin();it!=tab[nod].end();++it)
{
int need=*it;
if (!viz[need])
dfs(need);
}
}
int main()
{
fin >> nvf >> nmc ;
for (i=1;i<=nmc;++i)
{
fin >> x >> y;
tab[x].push_back(y);
tab[y].push_back(x);
}
crt=1;
dfs(crt);
sol=1;
for (i=1;i<=nvf;++i)
{
if (!viz[i])
{
dfs(i);
}
}
}