Pagini recente » Cod sursa (job #3223696) | Cod sursa (job #1031122) | Cod sursa (job #276372) | Cod sursa (job #344176) | Cod sursa (job #2156616)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
const int kMaxN = 1e5, kMaxM = 5e5;
ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");
vector<int> graph[kMaxN];
int edge_nodes[kMaxM];
bool used_edge[kMaxM];
void Df(const int node) {
for (auto&& edge : graph[node]) {
if (used_edge[edge]) {
continue;
}
used_edge[edge] = true;
Df(edge_nodes[edge] ^ node);
cout << node + 1 << ' ';
}
}
int main() {
int n, m; cin >> n >> m;
for (int i = 0; i < m; ++i) {
int x, y; cin >> x >> y; --x; --y;
graph[x].push_back(i);
graph[y].push_back(i);
edge_nodes[i] = x ^ y;
used_edge[i] = false;
}
if (any_of(graph, graph + n, [](const vector<int>& adj_list)
{ return adj_list.size() % 2 == 1; } )) {
cout << -1 << endl;
return 0;
}
Df(0);
}