Pagini recente » Cod sursa (job #1426238) | Cod sursa (job #2216625) | Cod sursa (job #2325820) | Cod sursa (job #1295605) | Cod sursa (job #373649)
Cod sursa(job #373649)
#include <stdio.h>
#define max 100010
struct lista
{
int muchie;
int nod;
lista *next;
};
lista *g[max];
int n,m,i,j,k,top,stack[max],deg[max];
char s[5*max];
void dfs(int nod)//dfs pe muchii
{
int w;
stack[++top]=nod;
while(top)
{
w=stack[top--]; printf("%d ",w);
for(; g[w]!=NULL; g[w]=g[w]->next)
if(!s[g[w]->muchie])
{
s[g[w]->muchie]=1;
stack[++top]=g[w]->nod;
}
}
}
void push(int i,int j,int k)
{
lista *p=new lista;
p->muchie=k;
p->nod=j;
p->next=g[i];
g[i]=p;
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d%d",&n,&m);
for(k=1; k<=m; k++)
{
scanf("%d%d",&i,&j);
push(i,j,k);
push(j,i,k);
deg[i]++; deg[j]++;
}
for(i=1; i<=n; i++)
if(deg[i]%2==1) { printf("-1"); return 0; }
dfs(1);
return 0;
}