Pagini recente » Cod sursa (job #2726086) | Cod sursa (job #1003993) | Cod sursa (job #2131395) | Cod sursa (job #1088683) | Cod sursa (job #1838615)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");
#define MAXN 100005
vector<int> graf[MAXN];
stack<int> st;
int n, m;
int main() {
int i,x, y, nod, delNod;
cin >> n >> m;
for(i=1; i<=m; i++) {
cin >> x >> y;
graf[x].push_back(y);
graf[y].push_back(x);
}
for(i=1; i<=n; i++)
if(!graf[i].size() || graf[i].size() % 2 != 0 ) {
cout<<-1;
return 0;
}
st.push(1);
while(!st.empty()) {
nod = st.top(); st.pop();
if(!graf[nod].size()) {
if(!st.empty())
cout<<nod<<" ";
} else {
delNod = graf[nod].back(); graf[nod].pop_back();
graf[delNod].erase( find(graf[delNod].begin(), graf[delNod].end(), nod) );
st.push(delNod);
}
}
return 0;
}