Pagini recente » Cod sursa (job #2442643) | Cod sursa (job #1608555) | Cod sursa (job #2685709) | Cod sursa (job #2147473) | Cod sursa (job #1918053)
#include <iostream>
#include <fstream>
#include <list>
#include <algorithm>
#define maxn 100005
#define maxm 500005
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
int n, m, stiva[maxm], vf;
list <int> l[maxn];
void read()
{
int x, y;
fin >> n >> m;
for (int i = 1; i <= m; i++) {
fin >> x >> y;
l[x].push_back(y);
l[y].push_back(x);
}
}
void solve()
{
int x, y;
vf = 1;
stiva[vf] = 1;
while (vf > 0) {
x = stiva[vf];
while (l[x].size() > 0) {
y = l[x].front();
l[x].pop_front();
l[y].erase(find(l[y].begin(), l[y].end(), x));
stiva[++vf] = y;
x = y;
}
fout << stiva[vf--] << ' ';
}
}
int main()
{
read();
//verificare ciclu eulerian
for (int i = 1; i <= n; i++) {
if (l[i].size() % 2 == 1) {
fout << -1;
return 0;
}
}
solve();
return 0;
}