from collections import * from itertools import * from functools import * from heapq import * import sys,math,time,random input = sys.stdin.readline INF = (1<<60) N,M,S,G = map(int,input().split()) e = [[] for _ in range(N)] dist = defaultdict(lambda:defaultdict(lambda:INF)) for _ in range(M): u,v,c = map(int,input().split()) e[u].append((v,c)) e[v].append((u,c)) dist[u][v] = c dist[v][u] = c def dijkstra(s,e): N = len(e) dist = [INF]*N dist[s]=0 h = [] heappush(h,(0,s)) while h: nw,v = heappop(h) if dist[v]!=nw: continue for iv,ic in e[v]: nc = ic + nw if nc < dist[iv]: dist[iv] = nc heappush(h,(nc,iv)) return dist D = dijkstra(G,e) X = [S] while X[-1]!=G: x = X[-1] for i in range(N): if D[i]+dist[i][x] == D[x]: X.append(i) break print(*X)