Pagini recente » Cod sursa (job #536753) | Clasament tl2 | Cod sursa (job #2815579) | Cod sursa (job #2043111) | Cod sursa (job #2232406)
#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 MAXBUF = 30000000;
char parseBuf[MAXBUF];
char *head;
bool isDigit[255];
void parseInit() {
int a = fread(parseBuf, 1, MAXBUF, stdin);
parseBuf[a] = 0;
head = parseBuf;
memset(isDigit, 0, sizeof isDigit);
for (int i = '0'; i <= '9'; ++i)
isDigit[i] = true;
}
int nextInt() {
int ans = 0;
for (; !isDigit[*head]; ++head);
for (; isDigit[*head]; ++head)
ans = ans * 10 + (*head) - '0';
return ans;
}
const int MAXN = 100010;
const int MAXM = 500010;
bool impar[MAXN];
int nxt[MAXM * 2], G[MAXN];
int to[MAXM * 2];
int done[(MAXM * 2) >> 5];
void writeInt(int x) {
char *ph = head;
for (; x; x /= 10)
*(ph++) = x % 10 + '0';
reverse(head, ph);
*(ph++) = ' ';
head = ph;
}
void DFS(int x) {
while (G[x] >= 0) {
int iy = G[x]; G[x] = nxt[G[x]];
SKIP(done[iy >> 5] & (1 << (iy & 31)));
done[iy >> 5] |= (1 << (iy & 31));
done[iy >> 5] |= (1 << ((iy ^ 1) & 31));
DFS(to[iy]);
}
writeInt(x + 1);
}
int main() {
assert(freopen(InFile, "r", stdin));
assert(freopen(OuFile, "w", stdout));
parseInit();
memset(G, 0xFF, sizeof G);
int N = nextInt(), M = nextInt();
for (int i = 0; i < M; ++i) {
int x = nextInt(), y = nextInt();
--x, --y;
impar[x] = !impar[x];
impar[y] = !impar[y];
to[2 * i] = y; nxt[2 * i] = G[x]; G[x] = 2 * i;
to[2 * i + 1] = x; nxt[2 * i + 1] = G[y]; G[y] = 2 * i + 1;
}
for (int i = 0; i < N; ++i)
if (G[i] == NULL || impar[i]) {
puts("-1");
return 0;
}
head = parseBuf;
DFS(0);
head -= 2;
for (; *head != ' '; --head);
fwrite(parseBuf, 1, head - parseBuf, stdout);
return 0;
}