Pagini recente » Cod sursa (job #2050642) | Cod sursa (job #3269396) | Cod sursa (job #1484183) | Cod sursa (job #1690643) | Cod sursa (job #1913599)
#include <vector>
#include <stdio.h>
#define NMAX 100010
#define MMAX 500010
using namespace std;
vector <int> G[NMAX];
bool fol[MMAX];
int n,m,i,from[MMAX],to[MMAX];
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d%d\n",&n,&m);
for(i=1;i<=m;++i){
int x,y;
scanf("%d%d",&x,&y);
G[x].push_back(i);
G[y].push_back(i);
from[i]=x;
to[i]=y;
}
bool ok=true;
for(i=1;i<=n&&ok==true;++i)
if(G[i].size()&1)
ok=false;
if(ok==false)
printf("-1\n");
else{
vector <int> st;
vector <int> sol;
st.push_back(1);
while(!st.empty()){
int nod=st.back();
if(!G[nod].empty()){
int e=G[nod].back();
G[nod].pop_back();
if(!fol[e]){
fol[e]=true;
int x=from[e];
if(x==nod)
x=to[e];
st.push_back(x);
}
}else{
st.pop_back();
sol.push_back(nod);
}
}
sol.pop_back();
for(vector <int>::iterator it=sol.begin();it<sol.end();++it)
printf("%d ",*it);
printf("\n");
}
return 0;
}