Pagini recente » Cod sursa (job #240324) | Cod sursa (job #1802565) | Cod sursa (job #2356603) | Cod sursa (job #399072) | Cod sursa (job #2570113)
#include <bits/stdc++.h>
using namespace std;
ifstream in("ciclueuler.in");
ofstream out("ciclueuler.out");
const int DIM = 1e5 + 7;
vector < pair <int,int> > l[DIM];
vector <int> rez;
int nr[DIM];
bool viz[5 * DIM];
void dfs(int x)
{
while(!l[x].empty())
{
int nod = l[x].back().first;
int poz = l[x].back().second;
l[x].pop_back();
if(viz[poz] == false)
{
viz[poz] = true;
dfs(nod);
}
}
rez.push_back(x);
}
int main()
{
int n, m;
in >> n >> m;
for(int i = 1; i <= m ; i++)
{
int x, y;
in >> x >> y;
l[x].push_back({y,i});
l[y].push_back({x,i});
nr[x]++;
nr[y]++;
}
for(int i = 1; i <= n; i++)
if(nr[i] % 2)
{
out << -1;
return 0;
}
dfs(1);
rez.pop_back();
for(int i = 0 ; i < rez.size(); i++)
out << rez[i] <<" ";
in.close();
out.close();
return 0;
}