from heapq import * from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] # 同じ距離のときにルートの辞書順が小さい方を選べばいいので # キーの2番目以降にルートを文字列でいれておいてダイクストラ def main(): n, m, s, g = MI() to = defaultdict(list) for _ in range(m): a, b, c = MI() to[a].append([b, c]) to[b].append([a, c]) hp = [] heappush(hp, [0, s]) fin = [False] * n while hp: d, *r = heappop(hp) u = r[-1] if u == g: print(*r) exit() if fin[u]: continue fin[u] = True for v, c in to[u]: if fin[v]: continue heappush(hp, [d + c] + r + [v]) main()