Pagini recente » Cod sursa (job #1740126) | Cod sursa (job #2861513) | Cod sursa (job #435196) | Cod sursa (job #1359341) | Cod sursa (job #393426)
Cod sursa(job #393426)
#include<fstream.h>
#include<iostream.h>
int a[10000][10000],i,n,k,nn,m;
int c[500000],euler[500000];
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
void citire()
{
int i,j;
f>>n>>m;
for(int t=1;t<=m;t++)
{
f>>i>>j;
a[i][j]=a[j][i]=1;
}
}
void ciclu(int euler[100],int &k,int nod)
{k=0;
int y=nod;
do
{ for(int i=1;i<=n;i++)
if(a[y][i])
{euler[++k]=i;
a[y][i]=a[i][y]=0;
y=i; break;
}
}
while(y!=nod);
}
int main()
{int j;
citire();c[1]=1;nn=1;
for(i=1;i<=nn;i++)
{
ciclu(euler,k,c[i]);
for(j=nn;j>i;j--)c[j+k]=c[j];
nn+=k;
for(j=1;j<=k;j++)
c[i+j]=euler[j];
}
for(i=1;i<=nn;i++)
g<<c[i]<<" ";
return 0;
}