#include using namespace std; const int kINF = 1 << 28; const int kMAX_N = 210; const int kMAX_M = kMAX_N * (kMAX_N - 1) / 2; int N, M, S, G; int cost[kMAX_N][kMAX_N]; int next_node[kMAX_N][kMAX_N]; int a[kMAX_M], b[kMAX_M], c[kMAX_M]; void WarshallFloyd() { for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (cost[i][j] > cost[i][k] + cost[k][j]) { cost[i][j] = cost[i][k] + cost[k][j]; next_node[i][j] = next_node[i][k]; } else if (cost[i][j] == cost[i][k] + cost[k][j] && next_node[i][j] > next_node[i][k]) { next_node[i][j] = next_node[i][k]; } } } } } /* void RestoreRoute(int node, int start, int goal) { cout << node << " " << start << " " << goal << endl; if (node == start) { cout << node; return; } RestoreRoute(next_node[start][node], start, goal); cout << " " << node; if (node == goal) { cout << endl; } } */ /* #include vector RestoreRoute(int node, int start, int goal) { if (node == start) { cout << node; return; } RestoreRoute(next_node[start][node], start, goal); cout << " " << node; if (node == goal) { cout << endl; } } */ void Solve() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) { cost[i][j] = 0; next_node[i][j] = kINF; } else { cost[i][j] = kINF; next_node[i][j] = j; } } } for (int i = 0; i < M; i++) { cost[a[i]][b[i]] = cost[b[i]][a[i]] = c[i]; } WarshallFloyd(); // RestoreRoute(G, S, G); /* int u, v; while (cin >> u >> v, u | v) { cout << "next " << next_node[u][v] << endl; } */ int node = S; cout << S; while (node != G) { node = next_node[node][G]; cout << " " << node; } cout << endl; /* cout << cost[S][G] << endl; int s, g; while (cin >> s >> g, s | g) { cout << next_node[s][g] << endl; } */ } int main() { cin >> N >> M >> S >> G; for (int i = 0; i < M; i++) { cin >> a[i] >> b[i] >> c[i]; } Solve(); return 0; }