Pagini recente » Cod sursa (job #2902087) | Cod sursa (job #1899671) | Cod sursa (job #1911625) | Cod sursa (job #377613) | Cod sursa (job #2596397)
#include <cstdio>
#include <vector>
using namespace std;
const int N = 100000 + 7;
const int M = 5 * N;
int n;
int m;
int Xor[M];
int sol[M];
int top;
vector<int> g[N];
bool used[M];
void dfs(int a) {
while (!g[a].empty()) {
int i = g[a].back();
g[a].pop_back();
if (used[i] == 0) {
used[i] = 1;
dfs(Xor[i] ^ a);
}
}
sol[++top] = a;
}
int main() {
freopen ("ciclueuler.in", "r", stdin);
freopen ("ciclueuler.out", "w", stdout);
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d %d", &x, &y);
Xor[i] = x ^ y;
g[x].push_back(i);
g[y].push_back(i);
}
for (int i = 1; i <= n; i++) {
if ((int) g[i].size() % 2 == 1) {
printf("-1\n");
return 0;
}
}
dfs(1);
for (int i = 1; i <= m; i++) {
printf("%d ", sol[i]);
}
printf("\n");
}