#include #include #include #define MAXN 100 #define INF 4000000L int n, m; unsigned long int (*d)[MAXN], (*q)[MAXN]; int main(void) { FILE *f, *g; int i, j, k; int x, y; unsigned long int z, z0; d = malloc(sizeof(long int) * MAXN * MAXN); q = malloc(sizeof(long int) * MAXN * MAXN); if (!d || !q) return 1; f = fopen("trip.in", "r"); if (!f || fscanf(f, "%d%d", &n, &m) != 2) return 1; for(i=0; i z && x != y) d[x][y] = d[y][x] = z; } fclose(f); z = INF; x = y = 0; for(i=0; i q[j][k] + d[k][i]) q[i][j] = q[j][k] + d[k][i]; q[j][i] = q[i][j]; } for(j=0; j q[j][i] + q[i][k]) q[j][k] = q[j][i] + q[i][k]; } d[x][y] = d[y][x] = INF; memcpy(q, d, sizeof(long int)*MAXN*MAXN); // memcpy(q, d, sizeof(q)); // Tohle snad ne!! for(i=0; i q[j][i] + q[i][k]) q[j][k] = q[j][i] + q[i][k]; g = fopen("trip.out", "w"); if (!g) return 2; if (z == INF) fprintf(g, "No solution.\n"); else { while (x != y) { fprintf(g, "%d ", y+1); for(i=0; i