Pagini recente » Cod sursa (job #1297649) | Cod sursa (job #1478860) | Cod sursa (job #1804340) | Cod sursa (job #33542) | Cod sursa (job #3285698)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
ifstream cin ("ciclueuler.in");
ofstream cout ("ciclueuler.out");
const int M = 5e5;
const int N = 1e5;
bool viz[M + 1];
int f[N + 1];
vector <int> sol;
vector <pair <int, int> > g[N + 1];
stack <int> s;
int n, m, x, y;
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; ++i)
{
cin >> x >> y;
f[x]++;
f[y]++;
g[x].push_back({y, i});
g[y].push_back({x, i});
}
for (int i = 1; i <= n; ++i)
if (f[i] & 1)
{
cout << "-1\n";
return 0;
}
s.push(1);
while (!s.empty())
{
int x = s.top();
if (!g[x].empty())
{
pair <int, int> node = g[x].back();
g[x].pop_back();
if (!viz[node.second])
viz[node.second] = 1, s.push(node.first);
}
else
sol.push_back(x), s.pop();
}
reverse (sol.begin(), sol.end());
for (auto it : sol)
cout << it << ' ';
return 0;
}