Pagini recente » Cod sursa (job #280424) | Cod sursa (job #2847677) | Cod sursa (job #2158108) | Cod sursa (job #2502553) | Cod sursa (job #2342298)
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
vector<int>G[100005];
int st[500005],stop=0;
inline void Euler(int node)
{
int other;
while(!G[node].empty())
{
st[++stop]=node;
other=G[node].back();
G[node].pop_back();
G[other].erase(find(G[other].begin(),G[other].end(),node));
node=other;
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
int n,x,y,i,m,now;
bool ok;
scanf("%d%d",&n,&m);
for(i=1;i<=m;++i)
{
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
ok=1;
for(i=1;i<=n;++i)
{
if(G[i].size()&1)
{
ok=0;
break;
}
}
if(ok==0)
printf("-1\n");
else
{
now=1;
stop=-1;
do
{
Euler(now);
now=st[stop];
printf("%d ",now);
stop--;
}
while(stop!=-1);
}
return 0;
}