Pagini recente » Cod sursa (job #2610786) | Cod sursa (job #2778475) | Cod sursa (job #1386322) | Cod sursa (job #1564865) | Cod sursa (job #1870624)
#include <fstream>
#include <vector>
#define SZ(x) ((int)(x).size())
using namespace std;
const int NMAX = 100000;
const int MMAX = 500000;
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] != -1) {
const int to = E[idx] ^ node;
E[idx] = -1;
fout << node + 1 << ' ';
dfs(to, fout);
}
}
}
int main() {
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
fin.tie(0);
ios_base::sync_with_stdio(false);
int n, m; fin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y; fin >> 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) {
fout << "-1\n";
return 0;
}
}
dfs(0, fout);
fout << "1\n";
return 0;
}