Pagini recente » Cod sursa (job #1275251) | Cod sursa (job #1577495) | Cod sursa (job #2091453) | Cod sursa (job #1924724) | Cod sursa (job #2121851)
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <algorithm>
#define MAX 100001
#define MAXM 500001
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
list <int> v[MAX];
int n, m;
void read()
{
int x, y;
fin >> n >> m;
for (int i = 0; i < m; ++i) {
fin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
}
void solve()
{
int vf = 1, stiva[MAXM], x, y;
stiva[vf] = 1;
while (vf > 0) {
x = stiva[vf];
while (v[x].empty() == false) {
y = v[x].front();
v[x].pop_front();
v[y].erase(find(v[y].begin(), v[y].end(), x));
stiva[++vf] = y;
x = y;
}
fout << stiva[vf--] << ' ';
}
}
int main()
{
read();
for (int i = 1; i <= n; ++i)
if (v[i].size() % 2 == 1) {
fout << -1;
return 0;
}
solve();
return 0;
}