from collections import deque INF = 1<<64 N,M,S,T = 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 i in range(N): G[i].sort() cost = [INF] * N cost[S] = 0 Queue = deque() Queue.append(S) while Queue: pos = Queue.popleft() for nxt,c in G[pos]: if cost[pos] + c < cost[nxt]: cost[nxt] = cost[pos] + c Queue.append(nxt) pos = T ans = [T] while pos != S: for nxt,c in G[pos]: if cost[pos] - c == cost[nxt]: ans.append(nxt) pos = nxt break print(*ans[::-1])