Pagini recente » Cod sursa (job #2945789) | Cod sursa (job #3248262) | Cod sursa (job #1958861) | Cod sursa (job #2580012) | Cod sursa (job #2567189)
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))
using namespace std;
int main() {
#ifdef HOME
ifstream cin("C.in");
ofstream cout("C.out");
#endif
ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");
int i, n, m;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
vector <vector <pair <int, int>>> g(n + 1);
for(i = 1; i <= m; i++) {
int x, y; cin >> x >> y;
g[x].push_back({y, i});
g[y].push_back({x, i});
}
for(i = 1; i <= n; i++) {
if(g[i].size() & 1) {
cout << -1;
return 0;
}
}
vector <bool> vis(m + 1);
vector <int> sol;
stack <int> stk;
stk.push(1);
while(stk.size()) {
int nod = stk.top();
while(g[nod].size() && vis[g[nod].back().second]) {
g[nod].pop_back();
}
if(g[nod].size()) {
stk.push(g[nod].back().first);
vis[g[nod].back().second] = 1;
}
else {
sol.push_back(nod);
stk.pop();
}
}
sol.pop_back();
for(auto it : sol) {
cout << it << " ";
}
return 0;
}