#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Node { int v; int parent; ll cost; Node(int v = -1, int parent = -1, ll cost = -1) { this->v = v; this->parent = parent; this->cost = cost; } bool operator>(const Node &n) const { return cost > n.cost; } }; ll g_cost[210][210]; vector E[210]; int main() { memset(g_cost, -1, sizeof(g_cost)); int N, M, S, G; cin >> N >> M >> S >> G; for (int i = 0; i < M; ++i) { int a, b, c; cin >> a >> b >> c; E[a].push_back(b); E[b].push_back(a); g_cost[a][b] = c; g_cost[b][a] = c; } priority_queue , greater> pque; pque.push(Node(S, -1, 0)); ll visited[N + 1]; memset(visited, -1, sizeof(visited)); int step_history[N + 1]; memset(step_history, -1, sizeof(step_history)); while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v] == -1) { visited[node.v] = node.cost; step_history[node.v] = node.parent; } else if (visited[node.v] < node.cost) { continue; } else { step_history[node.v] = min(step_history[node.v], node.parent); } for (int u : E[node.v]) { ll ncost = node.cost + g_cost[node.v][u]; pque.push(Node(u, node.v, ncost)); } } vector path; int cur = G; path.push_back(G); while (cur != S) { cur = step_history[cur]; path.push_back(cur); } reverse(path.begin(), path.end()); string ans = ""; for (int p : path) { ans += to_string(p); if (p != path.back()) ans += " "; } cout << ans << endl; return 0; }