Pagini recente » Cod sursa (job #191629) | Cod sursa (job #3277044) | Cod sursa (job #1954747) | Cod sursa (job #759086) | Cod sursa (job #1711614)
#include <fstream>
using namespace std;
ifstream cin ("ciclueuler.in");
ofstream cout ("ciclueuler.out");
int t[2][1000001],start[1000001],n,m,sol[500001],st[500001],vf=1,vf1,k;
void citire ()
{
cin>>n>>m; int x,y;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
++k; t[0][k]=x; t[1][k]=start[y]; start[y]=k;
++k; t[0][k]=y; t[1][k]=start[x]; start[x]=k;
} st[1]=1;
}
void sterge (int x,int x1)
{
int y=start[x];
while(y!=0)
{
if(t[0][y]==x1) { t[0][y]=-1; return; }
y=t[1][y];
}
}
void dfs ()
{
while(vf>0)
{
int x=start[st[vf]],ok=0;
while(x!=0)
{ if(t[0][x]!=-1) {
++vf; st[vf]=t[0][x]; ok=1; int a=t[0][x]; t[0][x]=-1; sterge(a,st[vf-1]); break;} x=t[1][x];
}
if(ok==0) {sol[++vf1]=st[vf]; vf--;}
}
}
void scrie ()
{
for(int i=1;i<=vf1;i++)
cout<<sol[i]<<" ";
}
int main()
{
citire();
dfs();
scrie();
return 0;
}