import heapq

n, m, S, G = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    adj[a].append((b, c))
    adj[b].append((a, c))

# Dijkstra's algorithm to find shortest distances
INF = float('inf')
dist = [INF] * n
dist[S] = 0
heap = []
heapq.heappush(heap, (0, S))

while heap:
    current_dist, u = heapq.heappop(heap)
    if current_dist > dist[u]:
        continue
    for v, cost in adj[u]:
        if dist[v] > dist[u] + cost:
            dist[v] = dist[u] + cost
            heapq.heappush(heap, (dist[v], v))

# Reconstruct the path from G to S by choosing lex smallest nodes
path = []
current = G
path.append(current)
while current != S:
    min_u = None
    for v, cost in adj[current]:
        if dist[v] + cost == dist[current]:
            if min_u is None or v < min_u:
                min_u = v
    current = min_u
    path.append(current)

# Reverse the path to get the correct order and print
print(' '.join(map(str, path[::-1])))