from collections import defaultdict from heapq import heapify, heappop, heappush n, m, s, g = map(int, input().split()) G = defaultdict(list) for _ in range(m): a, b, c = map(int, input().split()) G[a].append((b, c)) G[b].append((a, c)) for i in range(n): G[i].sort(key=lambda x: x[0]) INF = 10**18 DP = [INF for _ in range(n)] DP[s] = 0 H = [(0, s)] while H: cc, cp = heappop(H) if cc > DP[cp]: continue if cp == g: break for np, dc in G[cp]: nc = cc + dc if nc >= DP[np]: continue DP[np] = nc heappush(H, (nc, np)) ANS = [g] res = DP[g] while ANS[-1] != s: cp = ANS[-1] for np, dc in G[cp]: nc = res - dc if nc == DP[np]: ANS.append(np) res -= dc break ANS.reverse() print(*ANS)