Pagini recente » Cod sursa (job #1948849) | Cod sursa (job #2152876) | Cod sursa (job #2630607) | Cod sursa (job #1769112) | Cod sursa (job #2734076)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int N = 5e5 + 7;
vector<int> graph[N];
queue<int> ans;
void euler(int node) {
while (!graph[node].empty()) {
int child = graph[node].back();
graph[node].pop_back();
euler(child);
}
ans.emplace(node);
}
int main() {
int n, m;
fin >> n >> m;
for (int i = 1; i <= m; ++i) {
int x, y;
fin >> x >> y;
graph[x].emplace_back(y);
}
for (int i = 1; i <= n; ++i)
if (graph[i].size() & 1) {
fout << "-1";
return 0;
}
euler(1);
while (!ans.empty()) {
fout << ans.front() << " ";
ans.pop();
}
return 0;
}