Pagini recente » Cod sursa (job #2193416) | Cod sursa (job #3184572) | Cod sursa (job #1312266) | Cod sursa (job #1399073) | Cod sursa (job #1019107)
#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\n");
else DFS(1);
return 0;
}