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)) INF = float('inf') dist = [INF] * n prev = [-1] * n dist[S] = 0 heap = [] heapq.heappush(heap, (0, S)) while heap: d, u = heapq.heappop(heap) if d > dist[u]: continue for v, cost in adj[u]: new_dist = d + cost if new_dist < dist[v]: dist[v] = new_dist prev[v] = u heapq.heappush(heap, (new_dist, v)) elif new_dist == dist[v]: if prev[v] == -1 or u < prev[v]: prev[v] = u heapq.heappush(heap, (new_dist, v)) # Reconstruct path path = [] current = G while current != -1: path.append(current) current = prev[current] path = path[::-1] print(' '.join(map(str, path))) if __name__ == "__main__": main()