import heapq import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 10**9 N, M, S, G = map(int, input().split()) edge = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) edge[a].append((b, c)) edge[b].append((a, c)) dist = [inf] * N prev = [N] * N dist[S] = 0 que = [(0, S)] while que: ds, s = heapq.heappop(que) if dist[s] < ds: continue for t, dt in edge[s]: if dist[t] > ds + dt: dist[t] = ds + dt heapq.heappush(que, (ds + dt, t)) prev[t] = s elif dist[t] == ds + dt: if prev[t] > s: prev[t] = s heapq.heappush(que, (ds + dt, t)) ans = [] now = G while now < N: ans.append(now) now = prev[now] ans.reverse() print(*ans)