from queue import PriorityQueue N,M,S,G = list(map(int, input().split(' '))) C = [] for i in range(N): C.append([-1 for _ in range(N)]) for i in range(M): f,t,c = list(map(int, input().split(' '))) C[f][t] = c C[t][f] = c P = [] for i in range(N): P.append(-1) D = [] for i in range(N): D.append(float('inf')) D[G] = 0 Q = PriorityQueue() Q.put((0, G)) while not Q.empty(): d, f = Q.get() if D[f] < d: continue for t, c in enumerate(C[f]): if c != -1: nc = D[f] + c if nc < D[t]: D[t] = nc P[t] = f Q.put((D[t], t)) elif nc == D[t]: P[t] = min(P[t], f) s = S t = G solution = [] while s != t: solution.append(str(s)) s = P[s] solution.append(str(G)) print(' '.join(solution))