import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m, s, g = map(int, input().split()) edge = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) edge[a].append((c, b)) edge[b].append((c, a)) edge = [sorted(l, key=lambda x: x[1]) for l in edge] import heapq INF = 10**18 def dijkstra(s, edge): n = len(edge) dist = [INF]*n prev = [-1]*n dist[s] = 0 edgelist = [] heapq.heappush(edgelist,(dist[s], s)) while edgelist: minedge = heapq.heappop(edgelist) if dist[minedge[1]] < minedge[0]: continue v = minedge[1] for e in edge[v]: if dist[e[1]] > dist[v]+e[0]: dist[e[1]] = dist[v]+e[0] prev[e[1]] = v heapq.heappush(edgelist,(dist[e[1]], e[1])) return dist, prev d, p = dijkstra(g, edge) v = s ans = [s] while v != g: for c, u in edge[v]: if d[u]+c == d[v]: v = u break ans.append(v) print(*ans)