from heapq import * def dijkstra(start, goal): D[start] = 0 q = [] heappush(q, (0, start)) while len(q) > 0: d, u = heappop(q) if u == goal: return if d > D[u]: continue for v, c in E[u]: if D[v] == D[u] + c: if P[v] > u: P[v] = u if D[v] > D[u] + c: D[v] = D[u] + c heappush(q, (D[v], v)) P[v] = u return [] N,M,S,G = map(int,input().split()) ABC = [list(map(int,input().split())) for _ in range(M)] E = [[] for _ in range(N + 1)] for a, b, c in ABC: E[a].append([b, c]) E[b].append([a, c]) INF = 10 ** 7 D = [INF] * (N + 1) P = [-1] * (N + 1) dijkstra(S, G) now = G ans = [G] while now != S: now = P[now] ans.append(now) ans = reversed(ans) print(*ans)