#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heappush # %% N, M, S, G = map(int, readline().split()) m = map(int, read().split()) ABC = zip(m, m, m) # %% graph = [[] for _ in range(N)] for a, b, c in ABC: graph[a].append((b, c)) graph[b].append((a, c)) # %% INF = 10 ** 15 dist = [INF] * N dist[G] = 0 q = [G] while q: x = heappop(q) dv, v = divmod(x, 1 << 20) if dv > dist[v]: continue for w, cost in graph[v]: dw = dv + cost if dw >= dist[w]: continue dist[w] = dw heappush(q, (dw << 20) + w) # %% path = [S] while path[-1] != G: v = path[-1] for w, cost in sorted(graph[v]): if dist[v] - cost == dist[w]: path.append(w) break print(*path)