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 D = [] for i in range(N): D.append(float('inf')) D[S] = 0 P = [] for i in range(N): P.append(-1) Q = PriorityQueue() Q.put((0, S)) 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.insert(0, str(t)) t = P[t] solution.insert(0, str(S)) print(' '.join(solution))