Pagini recente » Cod sursa (job #1902259) | Cod sursa (job #1661839) | Cod sursa (job #1909539) | Cod sursa (job #974039) | Cod sursa (job #1909853)
#include<bits/stdc++.h>
#define in f
#define out g
using namespace std;
int const MAXSIZE = 100010;
int const MAXM = 500010;
int n, m, x, y;
vector<int> ans;
vector<int> graph[MAXSIZE];
stack<int> st;
int solve () {
st.push(1);
while (!st.empty()) {
int node = st.top();
if (graph[node].size() != 0) {
int adj = graph[node].back();
graph[node].pop_back();
int aux = 0;
for (int i = 0; i < graph[adj].size(); i++) {
if (graph[adj][i] == node && aux == 0) {
graph[adj].erase(graph[adj].begin() + i);
aux++;
}
}
st.push(adj);
} else {
ans.push_back(node);
st.pop();
}
}
}
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);
graph[x].push_back(y);
graph[y].push_back(x);
}
for (int i = 1; i <= n; i++) {
if (graph[i].size() % 2) {
out << -1;
return 0;
}
}
solve();
for (int i = 0; i < ans.size() - 1; i++)
printf("%d ", ans[i]);
}