Pagini recente » Cod sursa (job #2792261) | Cod sursa (job #2842158) | Cod sursa (job #2093656) | Cod sursa (job #1733302) | Cod sursa (job #1444497)
#include <cstdio>
#include <vector>
using namespace std;
const int N = 1000002;
int grad [N], st [5 * N];
pair <int, int> E [5 * N];
bool used [5 * N];
vector <int> graph [N], ans;
vector <int> :: iterator it [N];
int main () {
int n, m, i, x, y, fiu, ok;
vector <int> :: iterator jt;
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);
grad [x] ++;
grad [y] ++;
E [i] = make_pair (x, y);
graph [x].push_back (i);
graph [y].push_back (i);
}
for (i = 1; i <= n; i ++) {
if (grad [i] % 2) {
printf ("-1\n");
return 0;
}
it [i] = graph [i].begin ();
}
st [++ st [0]] = 1;
while (st [0]) {
x = st [st [0]];
ok = 1;
for (;it [x] != graph [x].end (); ++ it [x]) {
if (used [*it [x]])
continue;
if (E [*it [x]].first == x)
fiu = E [*it [x]].second;
else fiu = E [*it [x]].first;
used [*it [x]] = 1;
st [++ st [0]] = fiu;
ok = 0;
break;
}
if (ok) {
ans.push_back (x);
st [0] --;
}
}
for (jt = ans.begin (); jt != ans.end (); ++ jt)
printf ("%d ", *jt);
printf ("\n");
return 0;
}