import heapq n,m,S,G=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)) dst=[10**18]*n cfm=[False]*n pre=[None]*n q=[] heapq.heappush(q,(0,G,-1)) while q: now_d,now_place,pre_place=heapq.heappop(q) if cfm[now_place]: continue pre[now_place]=pre_place cfm[now_place]=True dst[now_place]=now_d for to_place,cost in g[now_place]: if cfm[to_place]: continue if dst[to_place]<=now_d+cost: continue dst[to_place]=now_d+cost heapq.heappush(q,(now_d+cost,to_place,now_place)) now=S;ans=[] while now!=G: tmp=10**18 ans.append(now) for to,cost in g[now]: if dst[to]+cost==dst[now]: tmp=min(tmp,to) now=tmp ans.append(G) print(*ans)