Pagini recente » Cod sursa (job #1673789) | Cod sursa (job #2507531) | Cod sursa (job #1478042) | Cod sursa (job #2673361) | Cod sursa (job #1019112)
#include <cstdio>
#include <list>
using namespace std;
int OK, i, N, M, x, y, Muchii[100001];
list<int> G[100001];
inline void DFS(int x)
{
int i,y=x;
list<int>::iterator it;
while (!G[y].empty())
{
printf("%d ", y);
i=G[y].back();
G[y].pop_back();
for (it=G[i].begin(); it!=G[i].end() && *it!=y; it++);
G[i].erase(it);
y=i;
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
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);
Muchii[x]++;
Muchii[y]++;
}
OK=1;
for (i=1; i<=N; i++)
if (Muchii[i]%2==1) OK=0;
if (!OK) printf("-1");
else DFS(1);
printf("\n");
return 0;
}