from collections import *

N, M, S, G = map(int, input().split())
inf = 10 ** 18
dp = [[inf] * N for i in range(N)]
for i in range(N):
    dp[i][i] = 0

Edge = defaultdict(lambda:inf)
for i in range(M):
    a, b, c = map(int, input().split())
    dp[a][b] = min(dp[a][b], c)
    dp[b][a] = min(dp[b][a], c)
    Edge[(a, b)] = min(Edge[(a, b)], c)
    Edge[(b, a)] = min(Edge[(b, a)], c)

for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

ans = [S]
now = S
cost = dp[now][G]
while now != G:
    for i in range(N):
        if i == now:
            continue
        if dp[now][i] + dp[i][G] == cost and Edge[now, i] == dp[now][i]:
            ans.append(i)
            cost -= dp[now][i]
            now = i
            break

print(*ans)