Pagini recente » Cod sursa (job #523512) | Cod sursa (job #3124678) | Cod sursa (job #1672156) | Cod sursa (job #2268816) | Cod sursa (job #2377057)
#include <fstream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
ifstream in("ciclueuler.in");
ofstream out("ciclueuler.out");
const int Nmax = 100005;
list<int> A[Nmax];
void solve (int&nod)
{
while (!A[nod].empty())
{
int nod_vecin = A[nod].front();
A[nod].pop_front();
A[nod_vecin].erase(find(A[nod_vecin].begin(), A[nod_vecin].end(), nod));
solve(nod_vecin);
}
out << nod << ' ';
}
int main()
{
int n, m, root = 1;
in.sync_with_stdio(false);
in >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y;
in >> x >> y;
A[x].push_back(y);
A[y].push_back(x);
}
for (int i = 1; i <= n; i++)
if (A[i].size() % 2)
{
out << -1;
return 0;
}
solve(root);
return 0;
}