Pagini recente » Cod sursa (job #2514652) | Cod sursa (job #2625910) | Cod sursa (job #809203) | Cod sursa (job #598667) | Cod sursa (job #2764094)
#include <bits/stdc++.h>
#define ll long long
#define nl '\n'
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define F0R(i, a, b) for (int i = a; i >= b; --i)
#define FORd(i, n) for (int i = 0; i < n; ++i)
#define F0Rd(i, n) for (int i = n - 1; i >= 0; --i)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxN = 1e5 + 5;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
int N, M;
vector<pair<int, int>> edges[mxN];
bitset<(int)5e5> used;
void euler(int node) {
for (pair<int, int> next_pair : edges[node]) {
int next_node = next_pair.second;
int curr_muchie = next_pair.first;
if (!used[curr_muchie]) {
used[curr_muchie] = true;
euler(next_node);
}
}
fout << node << " ";
}
void solve() {
fin >> N >> M;
for (int i = 0; i < M; ++i) {
int x, y;
fin >> x >> y;
edges[x].push_back({i, y});
edges[y].push_back({i, x});
}
for (int i = 1; i <= N; ++i) {
if (edges[i].size() % 2) {
fout << -1;
return;
}
}
euler(1);
}
int main() {
fin.tie(0); fout.tie(0);
ios::sync_with_stdio(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
//read the question correctly (ll vs int)
//what's the meaning of the problem ? Think outside the BOX !!!
//edge cases ?
//make it simple
//write everything (observations, edge cases, ideas, steps, methods, ...)