Pagini recente » Cod sursa (job #2755217) | Cod sursa (job #747130) | Cod sursa (job #3163140) | Cod sursa (job #2506550) | Cod sursa (job #1235621)
#include <cstdio>
#define max_m 500000
#define max_n 100000
struct node{
unsigned long inf;
node *next;
} *a[max_n];
unsigned long n,m,mm,x,y,crr,b;
unsigned long d[max_n];
//bool a[max_n][max_n];
void add_node(unsigned long x,unsigned long y){
node *c=new node;
c->inf=y;
c->next=a[x];
a[x]=c;
d[x]++;
c->inf=x;
c->next=a[y];
a[y]=c;
d[y]++;
}
bool perm(){
unsigned long f=1;
while(f<=n){
if(d[f]%2||!d[f])
break;
f++;
}
return f>n;
}
/*
void add_node(unsigned long x,unsigned long y){
a[x][y]=1;
a[y][x]=1;
d[x]++;
d[y]++;
}
bool perm(){
unsigned long f=1;
while(f<=n){
if(d[f]%2||!d[f])
break;
f++;
}
return f>n;
}
*/
int main(void){
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d%d",&n,&m);
mm=m;
while(mm){
scanf("%d%d",&x,&y);
add_node(x,y);
mm--;
}
if(perm()){
//mm=m;
crr=1;
while(m){
b=a[crr]->inf;
a[crr]=a[crr]->next;
printf("%d ",crr);
crr=b;
--m;
}
/*
crr=1;
//mm=m;
while(m){
mm=1;
while(!a[crr][mm])mm++;
a[crr][mm]=0;
a[mm][crr]=0;
printf("%d ",crr);
--m;
crr=mm;
}
*/
}
else
printf("%d",-1);
}