Pagini recente » Cod sursa (job #371956) | Cod sursa (job #2300515) | Cod sursa (job #3220375) | Cod sursa (job #307893) | Cod sursa (job #2323232)
#include <iostream>
#include <cstdio>
#include <list>
#include <algorithm>
#define NMAX 100010
#define MMAX 500010
using namespace std;
int n, m, sterse;
list<int> v[NMAX];
int stiv[MMAX], st;
void citire()
{
scanf("%d %d", &n, &m);
int t1, t2;
for (int i = 1; i <= m; i++)
{
scanf("%d %d", &t1, &t2);
v[t1].push_back(t2);
v[t2].push_back(t1);
}
}
void euler()
{
for (int i = 1; i <= n; i++)
if (v[i].size()%2)
{
printf("-1");
return;
}
stiv[++st] = 1;
while (st > 0)
{
int top = stiv[st];
if (v[top].empty())
{
printf("%d ", top);
st--;
}
else {
int next = v[top].front();
v[top].pop_front();
v[next].erase(std::find(v[next].begin(), v[next].end(), top));
stiv[++st] = next;
}
}
}
int main()
{
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
citire();
euler();
return 0;
}