import heapq def read_data(): N, M, S, G = map(int, input().split()) Es = [dict() for i in range(N)] for m in range(M): a, b, c = map(int, input().split()) Es[a][b] = c Es[b][a] = c return N, M, S, G, Es def solve(N, M, start, goal, Es): dist = [float('inf')] * N path = [tuple() for n in range(N)] dist[start] = 0 path[start] = (start, ) pq = [(0, path[start])] while pq: d, pathi = heapq.heappop(pq) v = pathi[-1] if v == goal: return pathi for u, nd in Es[v].items(): new_d = d + nd if (new_d < dist[u]) or (new_d == dist[u] and pathi + (u, ) < path[u]): dist[u] = new_d path[u] = pathi + (u, ) heapq.heappush(pq, (new_d, path[u])) if __name__ == '__main__': param = read_data() path = solve(*param) print(*path)