from collections import defaultdict, deque 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)] From = [-1 for _ in range(n)] DP[g] = 0 H = [(0, g)] while H: cc, cp = heappop(H) if cc > DP[cp]: continue for np, dc in G[cp]: nc = cc + dc if nc < DP[np]: DP[np] = nc From[np] = cp heappush(H, (nc, np)) elif nc == DP[np]: From[np] = min(From[np], cp) ANS = [s] while ANS[-1] != g: cp = From[ANS[-1]] ANS.append(cp) print(*ANS)