Pagini recente » Cod sursa (job #1037991) | Cod sursa (job #1755787) | Cod sursa (job #277716) | Cod sursa (job #2119879) | Cod sursa (job #1870638)
#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, vector<int>& cycle) {
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;
cycle.push_back(node);
cycle.push_back(to);
dfs(to, cycle);
}
}
}
int main() {
static long long eord, enew;
const unsigned sz = 1024 * 1024 * 1024;
static unsigned char *p = (unsigned char*)malloc(sz);
enew = ((long long)(p+sz-1) & ~0xff);
__asm__ volatile("mov %%esp, %0" : "=r"(eord));
__asm__ volatile("mov %0, %%esp" : : "r"(enew));
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;
}
}
vector<int> ans;
srand(time(0));
dfs(rand() % n, ans);
fout << 1 + ans.front();
for (int i = 1; i < SZ(ans); i += 2) {
fout << ' ' << 1 + ans[i];
}
fout << '\n';
__asm__ volatile("mov %0, %%esp" : : "r"(eord));
return 0;
}