Pagini recente » Cod sursa (job #983520) | Cod sursa (job #266255) | Cod sursa (job #575439) | Cod sursa (job #910383) | Cod sursa (job #2643474)
#include <iostream>
#include <fstream>
#include <vector>
#include <bitset>
using namespace std;
const int N = 100005;
const int M = 500005;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
vector<pair<int, int>> g[N]; // <destination, edge id>
vector<int> path;
bitset<M> used;
void euler(int node)
{
for(auto edge : g[node])
{
if(!used[edge.second])
{
used[edge.second] = true;
euler(edge.first);
}
}
path.push_back(node);
}
int main()
{
int n, m;
fin >> n >> m;
for(int i = 0; i < m; i++)
{
int x, y;
fin >> x >> y;
g[x].push_back({y, i});
g[y].push_back({x, i});
}
for(int i = 1; i <= n; i++)
{
if(g[i].size() % 2 != 0)
{
fout << -1;
return 0;
}
}
euler(1);
for(int node : path)
fout << node << ' ';
return 0;
}