Pagini recente » Cod sursa (job #1400961) | Cod sursa (job #1147336) | Cod sursa (job #1793810) | Cod sursa (job #895345) | Cod sursa (job #2865603)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int nmax = 500005;
int n, m, A[nmax], B[nmax], E[nmax], viz[nmax], nrm, cnt;
vector<int>V[nmax];
void DFS(int nod)
{
for(auto x : V[nod])
if(viz[x] == 0)
{
viz[x] = 1;
DFS(A[x] + B[x] - nod);
}
E[++cnt] = nod;
}
void Citire()
{
int x, y, i;
fin >> n >> m;
for(i = 1;i <= m;i++)
{
fin >> x >> y;
nrm++;
A[nrm] = x;
B[nrm] = y;
V[x].push_back(nrm);
V[y].push_back(nrm);
}
}
int viz1[100005];
void Defese(int nod)
{
viz1[nod] = 1;
for(auto x : V[nod])
if(viz1[x] == 0)
Defese(x);
}
void Solve()
{
int i;
for(i = 1;i <= n;i++)
if(V[i].size() % 2 == 1)
{
fout << "-1";
return;
}
DFS(1);
/*if(E[m] != E[1])
fout << "-1";
else*/
for(i = 1;i < cnt;i++)
fout << E[i] << " ";
}
int main()
{
Citire();
Solve();
return 0;
}