Pagini recente » Cod sursa (job #236936) | Cod sursa (job #149129) | Cod sursa (job #717629) | Cod sursa (job #9607) | Cod sursa (job #1919547)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin ("ciclueuler.in");
ofstream fout ("ciclueuler.out");
const int maxn = 1e5 + 5;
const int maxm = 5e5 + 5;
vector <int> G[maxn];
int Stk[maxm], top;
void Euler () {
int node, son;
Stk[++top] = 1;
while (top > 0) {
node = Stk[top];
while (G[node].size() > 0) {
son = G[node][0];
G[node].erase(G[node].begin());
G[son].erase(find(G[son].begin(), G[son].end(), node));
Stk[++top] = son;
node = son;
}
fout << Stk[top--] << ' ';
}
}
int main() {
ios_base :: sync_with_stdio (false);
int n, m, x, y, i;
fin >> n >> m;
for (i = 1; i <= m; i++) {
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
for (i = 1; i <= n; i++) {
if (G[i].size() & 1) {
fout << -1;
return 0;
}
}
Euler();
return 0;
}