Pagini recente » Cod sursa (job #1660593) | Cod sursa (job #2376396) | Cod sursa (job #376596) | Cod sursa (job #2455652) | Cod sursa (job #2001501)
#include <fstream>
#include <list>
#include <algorithm>
#define NMAX 100010
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int n,m,i,j,vf,x,y,st[NMAX*5];
list<int> l[NMAX];
int main()
{
f>>n>>m;
for(i=1;i<=m;++i) f>>x>>y,l[x].push_back(y),l[y].push_back(x);
for(i=1;i<=n;++i)
if(l[i].size()%2) {g<<-1<<'\n';return 0;}
vf=1,st[vf]=n;
while(vf>0)
{
x=st[vf];
while(!l[x].empty()) y=l[x].front(),l[x].pop_front(),l[y].erase(find(l[y].begin(),l[y].end(),x)),vf++,st[vf]=y,x=y;
g<<st[vf--]<<' ';
}
return 0;
}