from collections import defaultdict, deque INF = 1 << 60 N, M, S, G = map(int, input().split()) adj = defaultdict(list) for _ in range(M): a, b, c = map(int, input().split()) adj[a].append((b, c)) adj[b].append((a, c)) dists = [INF] * N q = deque([(0, G)]) # ゴールから探索する while q: d, v = q.popleft() if dists[v] <= d: continue dists[v] = d for to, cost in adj[v]: if dists[to] <= d + cost: continue q.append((d+cost, to)) # 経路復元 path = [S] # スタート地点から復元 while (v := path[-1]) != G: nv = INF # 次の頂点 for to, cost in adj[v]: if dists[to]+cost == dists[v]: nv = min(nv, to) assert nv != INF path.append(nv) print(*path)