Pagini recente » Cod sursa (job #626155) | Cod sursa (job #1312583) | Cod sursa (job #2634327) | Cod sursa (job #1106958) | Cod sursa (job #1018030)
#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;
list<int>::iterator it;
if (!G[x].empty())
{
printf("%d ", x);
i=G[x].back();
G[x].pop_back();
for (it=G[i].begin(); it!=G[i].end(); it++) if (*it==x) break;
G[i].erase(it);
DFS(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);
Muchii[x]++;
Muchii[y]++;
G[y].push_back(x);
}
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;
}