Pagini recente » Cod sursa (job #2587823) | Cod sursa (job #1641968) | Cod sursa (job #2699251)
#include <bits/stdc++.h>
#define ll long long
#define sz(v) (int)v.size()
using namespace std;
const int NMAX = 1e5 + 5;
vector<unordered_multiset<int>> graf(NMAX);
vector<int> ans;
int n, m;
bool ok = false;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
void dfs(int nod) {
while(!graf[nod].empty()) {
int x = *graf[nod].begin();
graf[nod].erase(graf[nod].begin());
graf[x].erase(graf[x].find(nod));
if(x != 1)
dfs(x);
}
ans.push_back(nod);
}
int main() {
//ifstream fin("date.in.txt");
fin >> n >> m;
for (int i = 1; i <= m; ++i) {
int a, b;
fin >> a >> b;
graf[a].insert(b);
graf[b].insert(a);
}
for (int i = 1; i <= n; ++i) {
if(sz(graf[i]) % 2 == 1) {
fout << -1;
return 0;
}
}
dfs(1);
for (int x : ans)
fout << x << " ";
return 0;
}