Pagini recente » Cod sursa (job #286003) | Cod sursa (job #1616414) | Cod sursa (job #2821700) | Cod sursa (job #1886846) | Cod sursa (job #1904558)
#include <cstdio>
#include <vector>
#define nmax 100001
#define mmax 500001
using namespace std;
vector <int> a[nmax],st,v;
unsigned int v1[mmax],v2[mmax];
unsigned int n,m,x,i,j,nod,muchie;
bool viz[mmax];
void citire()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d %d",&n,&m);
for(x=1;x<=m;x++)
{
scanf("%d %d",&i,&j);
a[i].push_back(x);
a[j].push_back(x);
v1[x]=i;
v2[x]=j;
}
}
void afisare()
{
for(x=0;x<v.size()-1;x++)
printf("%d ",v[x]);
printf("\n");
}
int main()
{
citire();
for(x=1;x<=n;x++)
if(a[x].size()%2)
{
printf("-1\n");
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(nod==v1[muchie]) st.push_back(v2[muchie]);
else st.push_back(v1[muchie]);
}
}
else
{
st.pop_back();
v.push_back(nod);
}
}
afisare();
return 0;
}