Pagini recente » Cod sursa (job #2247925) | Cod sursa (job #2452925) | Cod sursa (job #3041998) | Cod sursa (job #1621794) | Cod sursa (job #3268041)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
array<list<int>,100001> graph;
vector<int> ans;
array<int,100001> in,out;
stack<int> stk;
void solve(int node) {
stk.push(node);
while (!stk.empty()) {
int x = stk.top();
if (graph[x].empty()) {
ans.push_back(x);
stk.pop();
} else {
int y = graph[x].front();
graph[y].erase(find(graph[y].begin(),graph[y].end(),x));
graph[x].pop_front();
stk.push(y);
}
}
}
int n,m;
int main() {
fin >> n >> m;
for (int i = 1; i <= m; i++) {
int x,y;
fin >> x >> y;
in[x]++; out[x]++;
in[y]++; out[y]++;
graph[x].push_back(y);
graph[y].push_back(x);
}
bool ok = true;
for (int i = 1; i <= n; i++) {
if (in[i] % 2 or out[i] % 2) {
fout << -1;
return 0;
}
}
solve(1);
for (auto it = ans.rbegin(); it != ans.rend(); it++) {
fout << *it << ' ';
}
return 0;
}