Pagini recente » Cod sursa (job #2983154) | Cod sursa (job #2896197) | Cod sursa (job #1234754) | Cod sursa (job #106484) | Cod sursa (job #1689019)
#include <stdio.h>
#include <stack>
#include <vector>
#include <algorithm>
#define nmax 100010
using namespace std;
int n,m,x,y;
int rang[nmax];
stack <int> st;
vector <int> g[nmax];
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d %d",&n,&m);
for (int i=1;i<=m;i++) {
scanf("%d %d",&x,&y); g[x].push_back(y); g[y].push_back(x); rang[x]++; rang[y]++;
}
for (int i=1;i<=n;i++)
if (rang[i]%2==1) { puts("-1"); return 0; }
st.push(1);
while (!st.empty()) {
int x=st.top();
if (g[x].size()==0) {
printf("%d ",x); st.pop(); continue;
}
int y=g[x][g[x].size()-1];
st.push(y); g[x].pop_back();
g[y].erase(find(g[y].begin(),g[y].end(),x));
}
return 0;
}