#include #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]; } } } } } vector RestoreRoute(int node, int goal) { vector route; route.push_back(node); do { node = next_node[node][goal]; route.push_back(node); } while (node != goal); return route; } 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(); vector route = RestoreRoute(S, G); for (int i = 0; i < route.size(); i++) { cout << (i == 0 ? "" : " ") << route[i] << (i == route.size() - 1 ? "\n" : ""); } } int main() { cin >> N >> M >> S >> G; for (int i = 0; i < M; i++) { cin >> a[i] >> b[i] >> c[i]; } Solve(); return 0; }