Pagini recente » Cod sursa (job #3202795) | Cod sursa (job #2047889) | Cod sursa (job #1832140) | Cod sursa (job #1563143) | Cod sursa (job #1870661)
#include <fstream>
#include <vector>
#define SZ(x) ((int) (x).size())
using namespace std;
const int NMAX = 100000, MMAX = 500000;
const int NIL = -1;
vector<int> G[NMAX];
int E[MMAX];
void dfs(const int& node, ofstream& fout) {
while (not G[node].empty()) {
const int idx = G[node].back();
G[node].pop_back();
if (E[idx] != NIL) {
const int to = E[idx] ^ node;
E[idx] = NIL;
fout << 1 + node << ' ';
dfs(to, fout);
}
}
}
int main(void) {
ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, m; cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y; cin >> x >> y; x--; y--;
E[i] = x ^ y;
G[x].push_back(i);
G[y].push_back(i);
}
for (int i = 0; i < n; i++) {
if (SZ(G[i]) & 1) {
cout << "-1\n";
return 0;
}
}
dfs(0, cout);
}