Pagini recente » Cod sursa (job #2220544) | Cod sursa (job #2152675) | Cod sursa (job #1854190) | Cod sursa (job #2978275) | Cod sursa (job #2354605)
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
FILE*f=fopen("ciclueuler.in","r");
FILE*g=fopen("ciclueuler.out","w");
int k,gr[200005],n,m;
int st[500005];
struct nod{
int inf;
nod *urm;
} *l[100005];
void adaug(nod *&p,int x){
nod *u;
u=new nod;
u->inf=x;
u->urm=p;
p=u;
}
void sterg(nod *&p,int x){
nod *aux,*u;
u=p;
if(u->inf==x) {aux=p;
p=p->urm;
delete aux;
return;
}
while(u->urm&&u->urm->inf!=x) u=u->urm;
if(u->urm){
aux=u->urm;
u->urm=u->urm->urm;
delete aux;
}
}
int caut (nod*u,int x){
nod *p;
for(p=u;p;p=p->urm) if(p->inf==x) return 1;
return 0;
}
int main()
{
fscanf(f,"%d%d",&n,&m);
int i,x,y;
for(i=1;i<=m;i++){
fscanf(f,"%d%d",&x,&y);
adaug(l[x],y);
adaug(l[y],x);
gr[x]+=1;
gr[y]+=1;
}
for(i=1;i<=n;i++) if(gr[i]%2==1) {
fprintf(g,"-1");
return 0;}
for(i=1;i<=n;i++) {
int poz=0;
st[++poz]=1;
while(poz){
int x=st[poz];
if(l[x]){
int w=l[x]->inf;
st[++poz]=w;
if(l[w]) sterg(l[w],x);
if(l[x]) sterg(l[x],w);
}
else {fprintf(g,"%d ",st[poz--]);
k++;
if(k==m) return 0;
}
}
}
//cout<<k;
//for(i=1;i<=m;i++) fprintf(g,"%d ",sol[i]);
return 0;
}