Pagini recente » Cod sursa (job #2107255) | Cod sursa (job #2836293) | Cod sursa (job #1956736) | Cod sursa (job #2807865) | Cod sursa (job #2643586)
#include <iostream>
#include <fstream>
#include <vector>
#include <limits.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int N = 100005;
const int M = 500005;
// <destinatie, identificator muchie>
vector<pair<int, int>> g[N];
vector<int> ord;
bool viz[M];
int n, m;
void dfs(int nod)
{
for(auto y : g[nod])
{
int dest = y.first;
int id = y.second;
if(!viz[id])
{
viz[id] = true;
dfs(dest);
}
}
ord.push_back(nod);
}
int main()
{
cin >> n >> m;
for(int i = 0; i < m; i++)
{
int x, y;
cin >> x >> y;
g[x].push_back({y, i});
g[y].push_back({x, i});
}
// verificare
for(int i = 1; i <= n; i++)
if(g[i].size() % 2)
{
cout << -1;
return 0;
}
dfs(1);
ord.pop_back();
for(int x : ord)
cout << x << ' ';
return 0;
}