Pagini recente » Cod sursa (job #2820853) | Cod sursa (job #681490) | Cod sursa (job #1258262) | Monitorul de evaluare | Cod sursa (job #2215202)
#include <fstream>
#include <iostream>
#include <vector>
#include <list>
#define bsize (1<<16)+1
using namespace std;
vector <int> v[100003];
vector <int> :: iterator it;
list <int> q;
int i,y,n,nr,m,of,pos;
char ch[bsize+1];
int read (int &x)
{
x=0;
while (!isdigit(ch[pos]))
{
if (pos==bsize)
{
fread(ch,bsize,1,stdin);
pos=0;
}
else
{
pos++;
}
}
if (pos==bsize)
{
fread(ch,bsize,1,stdin);
}
while (isdigit(ch[pos]))
{
x=x*10+(ch[pos]-'0');
if (pos==bsize)
{
fread(ch,bsize,1,stdin);
pos=0;
}
else
{
pos++;
}
}
return x;
}
int x;
int main()
{
ios_base :: sync_with_stdio (false);
freopen ("ciclueuler.in","r",stdin);
freopen ("ciclueuler.out","w",stdout);
fread (ch,bsize,1,stdin);
read(n);
read(m);
for (i=1;i<=m;i++)
{
read(x);
read(y);
v[x].push_back(y);
v[y].push_back(x);
}
for (i=1;i<=n;i++)
{
if (v[i].size()%2!=0)
{
cout<<"-1";
return 0;
}
}
q.push_back(1);
while (!q.empty())
{
of=q.front();
x=of;
if (v[of].size()==0)
{
if (nr<m)
{
cout<<of<<" ";
nr++;
}
q.pop_front();
}
else
{
y=v[x].back();
q.push_front(y);
v[x].pop_back();
for (it=v[y].begin();it!=v[y].end();it++)
{
if (*it==x)
{
v[y].erase(it);
break;
}
}
}
}
return 0;
}