Pagini recente » Cod sursa (job #1375184) | Cod sursa (job #1173284) | Cod sursa (job #1622419) | Cod sursa (job #2076729) | Cod sursa (job #1966935)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int n,m,i,x,y,muchie,nod,v1[500005],v2[500005];
bool viz[500005];
vector <int> A[100005],st,v;
int main()
{
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
scanf("%d%d", &n, &m);
for(i=1; i<=m; i++)
{
scanf("%d%d", &x, &y);
A[x].push_back(i);
A[y].push_back(i);
v1[i]=x;
v2[i]=y;
}
for(i=1; i<=n; i++)
{
if(A[i].size()%2==1)
{printf("-1");
return 0;}
}
st.push_back(1);
while(!st.empty())
{
nod=st.back();
if(!A[nod].empty())
{
muchie=A[nod].back();
A[nod].pop_back();
if(!viz[muchie])
{viz[muchie]=true;
if(v1[muchie]==nod)
st.push_back(v2[muchie]);
else
st.push_back(v1[muchie]);}
}
else
{
st.pop_back();
v.push_back(nod);
}
}
for(i=0; i<v.size()-1; i++)
printf("%d ", v[i]);
return 0;
}