import heapq INF = 1 << 60 n, m, src, dst = map(int, input().split()) g = [[] for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) g[a].append((b, c)) g[b].append((a, c)) for u in range(n): g[u].sort(key=lambda x: x[0]) dist = [INF for _ in range(n)] dist[dst] = 0 hp = [(dist[dst], dst)] par = [None for _ in range(n)] while len(hp) > 0: cd, cur = heapq.heappop(hp) if cd > dist[cur]: continue for nxt, c in g[cur]: if dist[cur] + c < dist[nxt]: par[nxt] = cur dist[nxt] = dist[cur] + c heapq.heappush(hp, (dist[nxt], nxt)) cur = src ans = [] while True: ans.append(str(cur)) if cur == dst: break nxt = None for v, c in g[cur]: if dist[v] + c == dist[cur]: nxt = v break cur = nxt print(' '.join(ans))