Pagini recente » Cod sursa (job #2080962) | Cod sursa (job #2517294) | Cod sursa (job #2408153) | Cod sursa (job #725977) | Cod sursa (job #1427227)
#include <stdio.h>
using namespace std;
struct date {int m; date *next; };
date *t[100001],*a;
int n,m,i,j,rang[100001],x,y;
void euler(int x,int y)
{
int xx; date *a;
while (t[x]) {
xx=t[x]->m;
t[x]=t[x]->next;
a=t[xx];
if (a->m==x) t[xx]=t[xx]->next; else {
while (a->next->m!=x) a=a->next;
a->next=a->next->next;
}
euler(xx,y+1);
}
if (y>0) printf("%d ",x);
}
int main(){
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);
rang[x]++; rang[y]++;
a=new date; a->m=x; a->next=t[y]; t[y]=a;
a=new date; a->m=y; a->next=t[x]; t[x]=a;
}
bool ok=true;
for (i=1;i<=n;i++)
if (rang[i]%2==1) ok=false;
if (ok) euler(1,0); else printf("-1");
return 0;
}