Pagini recente » Cod sursa (job #2309443) | Cod sursa (job #845453) | Cod sursa (job #2790186) | Cod sursa (job #1591299) | Cod sursa (job #1628910)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int MAXN = 1e5 + 5;
const int MAXM = 5 * 1e5 + 5;
int n, m, odd, where = 1;
int x[MAXM], y[MAXM];
vector<int> g[MAXN], r;
bool vis[MAXM];
inline void euler(const int node) {
for (const auto i : g[node]) {
if (!vis[i]) {
vis[i] = true;
euler(x[i] + y[i] - node);
}
}
r.push_back(node);
}
int main() {
fin >> n >> m;
for (int i = 1; i <= m; ++i) {
fin >> x[i] >> y[i];
g[x[i]].push_back(i);
g[y[i]].push_back(i);
}
for (int i = 1; i <= n; ++i) {
odd += g[i].size() % 2;
if (g[i].size() % 2 == 1) {
where = i;
}
}
if (odd != 0 && odd != 2) {
fout << "-1\n";
} else {
euler(where);
}
for (const auto i : r) {
fout << i << ' ';
}
fout.close();
return 0;
}