import heapq def main(): n, m, S, G = map(int, input().split()) adj = [[] for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) adj[a].append((b, c)) adj[b].append((a, c)) dist = [float('inf')] * n path = [tuple() for _ in range(n)] dist[S] = 0 path[S] = (S,) heap = [] heapq.heappush(heap, (0, path[S])) while heap: current_cost, current_path = heapq.heappop(heap) u = current_path[-1] if u == G: print(' '.join(map(str, current_path))) return if current_cost > dist[u]: continue for v, c in adj[u]: new_cost = current_cost + c new_path = current_path + (v,) if new_cost < dist[v]: dist[v] = new_cost path[v] = new_path heapq.heappush(heap, (new_cost, new_path)) elif new_cost == dist[v] and new_path < path[v]: path[v] = new_path heapq.heappush(heap, (new_cost, new_path)) if __name__ == "__main__": main()