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] > (P[u] + [v]): P[v] = (P[u] + [v]) if D[v] > D[u] + c: D[v] = D[u] + c heappush(q, (D[v], v)) P[v] = (P[u] + [v]) 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 = [[] for _ in range(N + 1)] P[S] = [S] dijkstra(S, G) print(*P[G])