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[T] = 0 Queue = deque() Queue.append(T) 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 = S ans = [S] while pos != T: for nxt,c in G[pos]: if cost[pos] - c == cost[nxt]: ans.append(nxt) pos = nxt break print(*ans)