Pagini recente » Cod sursa (job #90108) | Cod sursa (job #964119) | Cod sursa (job #383042) | Cod sursa (job #2461758) | Cod sursa (job #2232400)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define mp make_pair
#define CHECK(x) if(!(x)) return false;
#define CHECKRET(x, y) if(!(x)) return (y);
#define SKIP(x) if((x)) continue;
typedef pair<int, int> pii;
#ifdef INFOARENA
#define ProblemName "ciclueuler"
#endif
#define MCONCAT(A, B) A B
#ifdef ProblemName
#define InFile MCONCAT(ProblemName, ".in")
#define OuFile MCONCAT(ProblemName, ".out")
#else
#define InFile "fis.in"
#define OuFile "fis.out"
#endif
const int MAXN = 100010;
const int MAXM = 500010;
struct node {
node *nxt;
int to;
} phys[MAXM * 2], *G[MAXN];
bool impar[MAXN];
vector<int> ciclu;
bool done[MAXM * 2];
void DFS(int x) {
while (G[x] != NULL) {
int iy = G[x] - phys; G[x] = G[x]->nxt;
SKIP(done[iy]);
done[iy] = done[iy ^ 1] = true;
DFS(phys[iy].to);
}
ciclu.push_back(x);
}
int main() {
assert(freopen(InFile, "r", stdin));
assert(freopen(OuFile, "w", stdout));
int N, M;
scanf("%d%d", &N, &M);
for (int i = 0; i < M; ++i) {
int x, y;
scanf("%d%d", &x, &y);
--x, --y;
impar[x] = !impar[x];
impar[y] = !impar[y];
phys[2 * i].to = y; phys[2 * i].nxt = G[x]; G[x] = &phys[2 * i];
phys[2 * i + 1].to = x; phys[2 * i + 1].nxt = G[y]; G[y] = &phys[2 * i + 1];
}
for (int i = 0; i < N; ++i)
if (G[i] == NULL || impar[i]) {
puts("-1");
return 0;
}
DFS(0);
ciclu.pop_back();
for (const auto &it : ciclu)
printf("%d ", it + 1);
puts("");
return 0;
}