Pagini recente » Cod sursa (job #2893053) | Cod sursa (job #482886) | Cod sursa (job #1360051) | Cod sursa (job #1675112) | Cod sursa (job #2699249)
#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) {
ans.push_back(nod);
//cout << nod << '\n';
/* for (int i = 1; i <= n; ++i) {
cout << i << " : ";
for (int x : graf[i])
cout << x << " ";
cout << '\n';
}
cout << '\n';*/
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);
}
}
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) {
cout << i << " : ";
for (int x : graf[i])
cout << x << " ";
cout << '\n';
}
*/
dfs(1);
if(sz(ans) == m) {
for (int x : ans)
cout << x << " ";
}
else
cout << -1;
return 0;
}