Pagini recente » Cod sursa (job #529920) | Cod sursa (job #2188809) | Cod sursa (job #1277647) | Cod sursa (job #1224868) | Cod sursa (job #2663363)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
struct xy { int x, y; };
const int maxn = 1e5+5, maxm = 5e5+5;
int n, m, x, y, rez;
int fr[maxn], done[maxm];
vector <xy> nod[maxn];
void euler(int x) {
if(rez >= m) { return; }
for(auto u : nod[x]) {
if(done[u.y] == 0) {
done[u.y] = 1;
euler(u.x);
}
}
if(rez < m) {
g << x << ' '; rez ++;
}
}
int main()
{
int i;
f >> n >> m;
for(i = 1; i <= m; i ++) {
f >> x >> y;
nod[x].push_back({y, i});
nod[y].push_back({x, i});
fr[x] ++; fr[y] ++;
}
for(i = 1; i <= n; i ++) {
if(fr[i] % 2 == 1) {
g << -1; return 0;
}
}
euler(1);
f.close(); g.close();
return 0;
}