Pagini recente » Cod sursa (job #2516372) | Cod sursa (job #499698) | Cod sursa (job #1581702) | Cod sursa (job #687654) | Cod sursa (job #1561882)
#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
int n, m;
vector<int>edge[N];
int main()
{
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
scanf("%d %d", &n, &m);
while(m --) {
int xx, yy;
scanf("%d %d", &xx, &yy); xx--; yy--;
edge[xx].push_back(yy); edge[yy].push_back(xx);
}
for(int i = 0; i < n; ++i)
if(edge[i].size() & 1) {
printf("%d", -1); return 0;
}
stack<int>vertex;
vertex.push(0);
vector<int>cycle;
while(!vertex.empty()) {
int act = vertex.top();
if(edge[act].size() == false) {
cycle.push_back(act); vertex.pop();
}
else {
int toAdd = edge[act].back(); edge[act].pop_back();
auto itnow = find(begin(edge[toAdd]), end(edge[toAdd]), act);
edge[toAdd].erase(itnow), vertex.push(toAdd);
}
}
cycle.pop_back();
for(int values : cycle)
printf("%d ", values + 1);
}