Pagini recente » Cod sursa (job #2798239) | Cod sursa (job #1729153) | Cod sursa (job #1172415) | Istoria paginii runda/bulangandit11 | Cod sursa (job #2328261)
#include <fstream>
#include <vector>
#include <bitset>
using namespace std;
ifstream cin ("ciclueuler.in");
ofstream cout ("ciclueuler.out");
int n, m, x, y;
int f[100005], ind[100005];
vector <pair <int, int>> g[100005];
bitset <500005> viz;
void dfs(int nod) {
for(; ind[nod] < g[nod].size(); ind[nod]++) {
if(!viz[g[nod][ind[nod]].second]) {
viz[g[nod][ind[nod]].second] = 1;
dfs(g[nod][ind[nod]].first);
}
}
if(m) {
cout << nod << " ";
m--;
}
}
int main() {
cin >> n >> m;
for(int i = 1; i <= m; i++) {
cin >> x >> y;
g[x].push_back({y, i});
g[y].push_back({x, i});
f[x]++; f[y]++;
}
for(int i = 1; i <= n; i++) {
if(f[i] % 2) {
cout << -1;
return 0;
}
}
dfs(1);
return 0;
}