Pagini recente » Cod sursa (job #1652696) | Cod sursa (job #1914161) | Cod sursa (job #859509) | Cod sursa (job #2848309) | Cod sursa (job #245185)
Cod sursa(job #245185)
using namespace std;
#include <bitset>
#include <vector>
#define pb push_back
#define sz size
#define f first
#define s second
#define II inline
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define mp make_pair
#define IN "ciclueuler.in"
#define OUT "ciclueuler.out"
#define N_MAX 1<<17
#define M_MAX 1<<19
int last,N,M;
vector<int> A[N_MAX];
int stv[M_MAX],nr[M_MAX],Q[M_MAX],G[N_MAX],X[M_MAX],Y[M_MAX];
bool viz[M_MAX];
int main()
{
freopen(IN,"r",stdin);
freopen(OUT,"w",stdout);
scanf("%d %d",&N,&M);
FOR(i,1,M)
{
scanf("%d %d",X+i,Y+i);
A[X[i]].pb(i);
A[Y[i]].pb(i);
++G[X[i]],++G[Y[i]];
}
FOR(i,1,N)
if(G[i]&1)
{
printf("-1\n");
return 0;
}
int top(0),nod,vx;
for(stv[++top] = nod = 1;nod;)
{
for(;nr[top] < G[ stv[top] ];)
{
nod = stv[top];
vx = A[nod][nr[top]++];
if(viz[vx])
continue;
viz[vx] = true;
if(nod == X[vx])
stv[++top] = Y[vx];
else
stv[++top] = X[vx];
nr[top] = 0;
}
Q[++last] = nod;
nod = stv[--top];
}
if(--last < M)
{
printf("-1\n");
return 0;
}
FOR(i,1,last)
printf("%d ",Q[i]);
return 0;
}