#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)); } vector dist(N + 1, LLONG_MAX); priority_queue , greater> pque; pque.push(Node(G, -1, 0)); while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (dist[node.v] <= node.cost) continue; dist[node.v] = node.cost; for (auto e : E[node.v]) { ll ncost = node.cost + e.cost; pque.push(Node(e.u, node.v, ncost)); } } vector ans; int cur = S; ans.push_back(cur); while (true) { int next = 1 << 29; for (Edge &e : E[cur]) { if (dist[cur] == dist[e.u] + e.cost) { next = min(next, e.u); } } cur = next; ans.push_back(cur); if (cur == G) break; } for (int v : ans) { cout << v; if (v != ans.back()) cout << " "; } cout << endl; return 0; }