INF = 1e18 from heapq import heappush, heappop def main(): N, M, S, T = map(int, input().split()) G = [list() for _ in range(N)] for i in range(M): u, v, w = map(int, input().split()) G[u].append((v, w)) G[v].append((u, w)) # T --> S に最短距離 kakutei = [False] * (N) prev = [N]*N dist = [INF] * (N) dist[T] = 0 prev[T] = -1 que = [] heappush(que, (0, -1, T)) while que: curr_dist, pre, pos = heappop(que) if kakutei[pos]: continue kakutei[pos] = True prev[pos] = pre for nex, kyori in G[pos]: if kakutei[nex]: continue if dist[nex] >= curr_dist + kyori: dist[nex] = curr_dist + kyori heappush(que, (dist[nex], pos, nex)) ans = [] pos = S while pos != -1: ans.append(pos) pos = prev[pos] print(*ans) if __name__ == "__main__": main()