Pagini recente » Cod sursa (job #1104233) | Cod sursa (job #3277341) | Cod sursa (job #510253) | Cod sursa (job #3280412) | Cod sursa (job #3286226)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int nMax = 1e5 + 1;
const int mMax = 5e5 + 1;
int n, m;
vector<pair<int,int>> graph[nMax];
vector<int> cycle;
bitset<mMax> v;
void euler(int node)
{
while(!graph[node].empty())
{
int next = graph[node].back().first;
int edge = graph[node].back().second;
graph[node].pop_back();
if(v[edge])
continue;
v[edge] = 1;
euler(next);
}
cycle.push_back(node);
}
int main()
{
ios::sync_with_stdio(false);
fin.tie(nullptr);
fin >> n >> m;
for(int i = 1; i <= m; ++i)
{
int x, y;
fin >> x >> y;
graph[x].push_back({y, i});
graph[y].push_back({x, i});
}
for(int i = 1; i <= n; ++i)
if(graph[i].size() % 2)
{
fout << -1;
return 0;
}
euler(1);
for(int i: cycle)
fout << i << " ";
fin.close();
fout.close();
return 0;
}