Pagini recente » Cod sursa (job #388007) | Cod sursa (job #1076745) | Cod sursa (job #2475039) | Cod sursa (job #1377795) | Cod sursa (job #1897255)
#include <fstream>
using namespace std;
ifstream cin ("ciclueuler.in");
ofstream cout ("ciclueuler.out");
int n,m;
struct bla
{
int nod,urm;
} t[1000010];
int start[100010];
int st[100010],vf;
int used[100010];
void read ()
{ int a,b,k=0;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>a>>b;
t[++k].nod=b; t[k].urm=start[a]; start[a]=k;
t[++k].nod=a; t[k].urm=start[b]; start[b]=k;
}
}
void up_date(int a,int b)
{
for(int x=start[a];x;x=t[x].urm)
if(t[x].nod==b) { t[x].nod=-1; return; }
}
void df_iterativ ()
{ cout<<1<<" ";
vf=1; st[1]=1;
while(vf>0)
{ int nr=0;
for(int x=start[st[vf]];x;x=t[x].urm)
{
if(t[x].nod!=-1)
{
st[++vf]=t[x].nod; t[x].nod=-1; up_date(st[vf],st[vf-1]); nr=1; start[st[vf-1]]=t[x].urm; break;
}
}
if(nr==0)
{
if(st[vf]!=1) cout<<st[vf]<<" "; vf--;
}
}
}
int main()
{
read();
df_iterativ();
cin.close();
cout.close();
return 0;
}