#include #define INF 1000000000 #define min(a, b) (((a) < (b)) ? (a) : (b)) int adj[200][200]; int next[200][200]; void warshall_floyd(int n) { int i, j, k; for (k = 0; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (adj[i][k] + adj[k][j] < adj[i][j]) { adj[i][j] = adj[i][k] + adj[k][j]; next[i][j] = next[i][k]; } else if (adj[i][k] + adj[k][j] == adj[i][j]) next[i][j] = min(next[i][j], next[i][k]); } void printPath(int s, int g) { for (; s != g; s = next[s][g]) printf("%d ", s); printf("%d\n", g); } int main(void) { int i, j; int n, m, s, g; scanf("%d %d %d %d", &n, &m, &s, &g); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { adj[i][j] = INF; next[i][j] = j; } while (m--) { int a, b, c; scanf("%d %d %d", &a, &b, &c); adj[a][b] = adj[b][a] = c; } warshall_floyd(n); printPath(s, g); return 0; }