#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; } }; struct Edge { int u; ll cost; Edge(int u, ll cost) { this->u = u; this->cost = cost; } }; vector E[210]; int main() { 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(Edge(b, c)); E[b].push_back(Edge(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 (auto e : E[node.v]) { ll ncost = node.cost + e.cost; pque.push(Node(e.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; }