Pagini recente » Cod sursa (job #390568) | Cod sursa (job #1774299) | Cod sursa (job #2749070) | Cod sursa (job #1899437) | Cod sursa (job #1870670)
#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) {
static long long eord, enew;
const unsigned m_size = 512 * 512 * 512;
static unsigned char* p = (unsigned char*) malloc(m_size);
enew = ((long long)(p + m_size - 1) & ~0xff);
__asm__ volatile("mov %%esp, %0" : "=r"(eord));
__asm__ volatile("mov %0, %%esp" : : "r"(enew));
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);
cout << '\n'; cout.close();
__asm__ volatile("mov %0, %%esp" : : "r"(eord));
}