Pagini recente » Cod sursa (job #54243) | Cod sursa (job #2494836) | Cod sursa (job #1995471) | Cod sursa (job #1445381) | Cod sursa (job #1612180)
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");
int n,m,i,j,*a[101],fv[101],nr,sta;
stack<int> T;
queue<int> F;
void DFS(int Vf)
{
T.push(Vf);
for(int z=1;z<=a[Vf][0];++z)
{
if(a[Vf][z]!=0)
{
int aux=a[Vf][z],zz=0;
a[Vf][z]=0;
while(a[aux][zz]!=Vf)
++zz;
a[aux][zz]=0;
DFS(aux);
}
}
F.push(T.top());
T.pop();
}
int main()
{
cin>>n>>m;
for(int x=1;x<=n;++x)
{
a[x]=(int*)realloc(a[x],sizeof(int)*2);
a[x][0]=0;
}
for(int x=1;x<=m;++x)
{
cin>>i>>j;
a[i]=(int*)realloc(a[i],sizeof(int)*(a[i][0]+2));
++a[i][0];
a[i][a[i][0]]=j;
a[j]=(int*)realloc(a[j],sizeof(int)*(a[j][0]+2));
++a[j][0];
a[j][a[j][0]]=i;
}
DFS(1);
while(!T.empty())
{
F.push(T.top());
T.pop();
}
while(!F.empty())
{
cout<<F.front()<<' ';
F.pop();
}
return 0;
}