Pagini recente » Cod sursa (job #1135245) | Cod sursa (job #883357) | Cod sursa (job #1981240) | Cod sursa (job #2207748) | Cod sursa (job #1019504)
#include<cstdio>
#include<list>
#define N_MAX 100010
#define M_MAX 500010
using namespace std;
list <int> G[N_MAX];
inline bool verif(int n)
{
int i;
for (i=1;i<=n;i++)
if (G[i].size()%2==1) return false;
return true;
}
inline void euler()
{
int x,y;
list <int> :: iterator it;
x=1;
while (!G[x].empty())
{
printf("%d ",x);
y=G[x].back();
G[x].pop_back();
for (it=G[y].begin();it!=G[y].end();it++)
if (*it==x)
{
G[y].erase(it);
break;
}
x=y;
}
}
inline void load()
{
int i,M,N,x,y;
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);
}
if (verif(N)) euler();
else printf("-1");
printf("\n");
}
int main()
{
freopen("ciceuler.in","r",stdin);
freopen("ciceuler.out","w",stdout);
load();
fclose(stdin);
fclose(stdout);
return 0;
}