Pagini recente » Cod sursa (job #521101) | Cod sursa (job #2165253) | Cod sursa (job #1802210) | Cod sursa (job #2552908) | Cod sursa (job #2092200)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
struct nod {
int inf,ok=0;
nod *urm;
}*l[100005];
int n,m,a[500005],ok,nr;
void adaug(nod *&p,int x) {
nod *c;
c=new nod;
c->inf=x;
c->urm=p;
p=c;
}
void caut(nod *&p,int x,int k) {
nod *c;
for (c=p;c;c=c->urm)
if (c->inf==x && c->ok==0) {
c->ok=k;
break;
}
}
void euler(int i) {
nod *j;
for (j=l[i];j;j=j->urm)
if (j->ok==0){
j->ok=1;
caut(l[j->inf],i,1);
euler(j->inf);
}
a[++nr]=i;
}
void afis() {
int i;
for (i=1;i<nr;i++)
g<<a[i]<<' ';
}
int main() {
int i,x,y;
nod *c;
f>>n>>m;
for (i=1;i<=m;i++) {
f>>x>>y;
if (x==y) adaug(l[x],y);
else {
adaug(l[x],y);
adaug(l[y],x);
}
}
euler(1);
ok=1;
for (i=1;i<=n;i++)
for (c=l[i];c;c=c->urm)
if (c->ok==0) {
ok=0;
break;
}
if (ok) afis();
else g<<"-1";
return 0;
}