Pagini recente » Cod sursa (job #14395) | Cod sursa (job #655798) | Cod sursa (job #1445071) | Cod sursa (job #63009) | Cod sursa (job #1478198)
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#define nmax 100010
using namespace std;
int n,m,i,j,x,y,rang[nmax];
vector <int> g[nmax],sol;
stack <int> st;
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);
g[x].push_back(y); g[y].push_back(x); rang[x]++; rang[y]++;
}
for (i=1;i<=n;i++)
if (rang[i]%2==1) { printf("-1"); return 0; }
st.push(1);
while (!st.empty()) {
x=st.top();
if (g[x].size()==0) {
sol.push_back(x); st.pop();
} else
{
y=g[x][g[x].size()-1]; g[x].pop_back();
st.push(y);
g[y].erase(find(g[y].begin(),g[y].end(),x));
}
}
for (i=0;i<sol.size();i++) printf("%d ",sol[i]);
return 0;
}