Pagini recente » Cod sursa (job #1631466) | Cod sursa (job #268873) | Cod sursa (job #3170455) | Cod sursa (job #1000244) | Cod sursa (job #2121069)
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <bitset>
using namespace std;
const int MAXM = 500005;
const int MAXN = 100005;
int n, m;
struct M{
int x, y;
bool removed;
M() : removed(0) { }
};
vector<M> muchii;
vector<int> graf[MAXN];
stack<int> st;
int main() {
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
scanf("%d %d ", &n, &m);
M k;
for (int i = 0; i < m; i++) {
scanf("%d %d ", &k.x, &k.y);
muchii.push_back(k);
graf[k.x].push_back(i);
graf[k.y].push_back(i);
}
for (int i = 1; i <= n; i++)
if (graf[i].size() % 2) {
printf("-1\n");
exit(0);
}
st.push(1);
while (!st.empty()) {
int x = st.top();
if (!graf[x].empty()) {
int it = graf[x].back();
graf[x].pop_back();
if(!muchii[it].removed) {
muchii[it].removed = 1;
int toAdd = x != muchii[it].x ? muchii[it].x : muchii[it].y;
st.push(toAdd);
continue;
}
} else {
st.pop();
printf("%d ", x);
}
}
return 0;
}