Pagini recente » Cod sursa (job #1197265) | Cod sursa (job #2364383) | Cod sursa (job #806085) | Cod sursa (job #2338253) | Cod sursa (job #1038178)
#include<cstdio>
#include<utility>
using namespace std;
pair <int,int> a[500005],st[500005];
int n,m,nr,x,y;
bool ok,ap[500005];
void tipar()
{
int i;
for (i=1;i<=m;++i)
printf("%d ",st[i].first);
printf("\n");
}
void back(int k)
{
int i;
for (i=1;i<=m && !ok;++i)
if (!ap[i])
{
ap[i]=true;
st[k]=a[i];
if (i>1 && st[k-1].second!=st[k].first)
goto parttwo;
if (k==m && st[k].second==st[1].first)
{
tipar();
ok=true;
}
else if (k<m) back(k+1);
parttwo:
if (a[i].first!=a[i].second)
{
st[k]=make_pair(a[i].second,a[i].first);
if (i>1 && st[k-1].second!=st[k].first)
{
ap[i]=false;
continue;
}
if (k==m && st[k].second==st[1].first)
{
tipar();
ok=true;
}
else if (k<m) back(k+1);
}
ap[i]=false;
}
}
int main()
{
int i;
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d%d",&n,&m);
for (i=1;i<=m;++i)
{
scanf("%d%d",&x,&y);
a[i]=make_pair(x,y);
}
back(1);
if (!ok) printf("-1\n");
return 0;
}