N,M,S,GG = 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)) import heapq inf = 10 ** 8 dist = [inf] * N dist[GG] = 0 q = [(0,GG)] while q: d,now = heapq.heappop(q) if dist[now] < d:continue for v,c in G[now]: if dist[v] > d + c: dist[v] = d + c heapq.heappush(q,(d+c,v)) #print(dist) ans = [] now = S while now != GG: ans.append(now) _min = N + 5 for v,c in G[now]: if dist[v] == dist[now] - c: if v < _min: _min = v now = _min ans.append(GG) print(*ans)