Pagini recente » Cod sursa (job #3039306) | Cod sursa (job #1605937) | Cod sursa (job #2785780) | Cod sursa (job #579504) | Cod sursa (job #2565083)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int nmax = 100005, mmax = 500005;
int n, m;
struct vec {
int to, i;
};
stack < vec, vector<vec> > l[nmax];
vector < int > v; // nmax
bitset < mmax > viz;
void Dfs(int nod)
{
while (!l[nod].empty())
{
int to = l[nod].top().to;
int i = l[nod].top().i;
l[nod].pop();
if (!viz[i])
{
viz[i] = 1;
Dfs(to);
}
}
v.push_back(nod);
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= m; i++)
{
int a, b;
fin >> a >> b;
l[a].push({b, i});
l[b].push({a, i});
}
for (int i = 1; i <= n; i++)
{
if (l[i].size() % 2)
{
fout << -1;
fin.close();
fout.close();
return 0;
}
}
Dfs(1);
for (int i = 0; i < v.size() - 1; i++)
fout << v[i] << ' ';
fin.close();
fout.close();
return 0;
}