Pagini recente » Cod sursa (job #1105188) | Cod sursa (job #546427) | Cod sursa (job #2733514) | Cod sursa (job #3246845) | Cod sursa (job #1058336)
#include<cstdio>
#include<vector>
using namespace std;
int n,m,ok,stv[500010],h,el;
vector<int>v[100010];
void citire()
{
int x,y;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
ok=0;
for(int i=1;i<=n;i++)
if(v[i].size()%2!=0)
{
ok=-1;
break;
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
citire();int x;
if(ok==-1)
printf("%d",ok);
else
{
stv[1]=1;
h=1;
while(h!=0)
{
x=stv[h];
if(!v[x].empty())
{
stv[++h]=v[x][0];
el=v[x][0];
v[x][0]=v[x].back();
v[x].pop_back();
for(int i=0;i<v[el].size();i++)
{
if(v[el][i]==x)
{
v[el][i]=v[el].back();
v[el].pop_back();
break;
}
}
}
else
{
while(h!=0 && v[stv[h]].empty())
{
printf("%d ",stv[h]);
h--;
}
}
}
}
}