Pagini recente » Cod sursa (job #1348959) | Rating Greere Stefan (Stefangreere) | Cod sursa (job #2654385) | Cod sursa (job #552019) | Cod sursa (job #3142675)
#include <fstream>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
int n, m, i, x, y, r[500002];
int a[100002][100002];
bool ok;
void afis() {
ok = true;
for(int i = 1; i <= m; i++) fout << r[i] << " ";
}
void Ciclu(int x, int k) {
for(int i = 1; i <= n; i++) {
if(ok) break;
if(a[x][i]) {
r[k] = i;
a[x][y] = a[x][y] - 1;
a[y][x] = a[y][x] - 1;
if(k == m + 1) afis();
else Ciclu(i, k + 1);
a[x][y] = a[x][y] + 1;
a[y][x] = a[y][x] + 1;
}
}
}
int main() {
fin >> n >> m;
for(i = 1; i <= m; i++) {
fin >> x >> y;
a[x][y] = a[x][y] + 1;
a[y][x] = a[y][x] + 1;
}
for(i = 1; i <= n; i++) {
r[1] = i;
Ciclu(i, 2);
}
return 0;
}