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[G]=0 Q=[] Q.append((0,G)) 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=S ANS=[S] while now!=G: now=FROM[now] ANS.append(now) print(*ANS)