from heapq import heappop,heappush N,M,S,G=map(int,input().split()) E=[[] for i in range(N+1)] for i in range(M): a,b,c=map(int,input().split()) E[a].append((b,c)) E[b].append((a,c)) D=[1<<30]*(N+1) FROM=[-1]*(N+1) D[S]=0 Q=[] Q.append((0,S)) while Q: time,now=heappop(Q) if D[now]!=time: continue for to,cost in E[now]: if D[to]>time+cost: D[to]=time+cost heappush(Q,(D[to],to)) FROM[to]=now elif D[to]==time+cost: FROM[to]=min(FROM[to],now) now=G ANS=[G] while now!=S: now=FROM[now] ANS.append(now) print(*ANS[::-1])