import java.util.*; import java.math.*; public class Main { static int[] base; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int s = sc.nextInt(); int g = sc.nextInt(); ArrayList[] graph = new ArrayList[n]; for (int i = 0; i < n; i++) { graph[i] = new ArrayList(); } for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); graph[a].add(new Path(b, c)); graph[b].add(new Path(a, c)); } PriorityQueue queue = new PriorityQueue<>(); ArrayList list = new ArrayList<>(); list.add(s); queue.add(new Route(s, 0, list)); Route[] routes = new Route[n]; while (queue.size() > 0) { Route r = queue.poll(); if (routes[r.to] != null) { continue; } routes[r.to] = r; for (Path p : graph[r.to]) { ArrayList newList = new ArrayList<>(r.name); newList.add(p.to); queue.add(new Route(p.to, r.score + p.score, newList)); } } StringBuilder sbr = new StringBuilder(); for (int i = 0; i < routes[g].name.size(); i++) { if (i != 0) { sbr.append(" "); } sbr.append(routes[g].name.get(i)); } System.out.println(sbr); } static class Route implements Comparable { int to; int score; ArrayList name; public Route (int to, int score, ArrayList name) { this.to = to; this.score = score; this.name = name; } public int compareTo(Route another) { if (score == another.score) { for (int i = 0; i < name.size() && i < another.name.size(); i++) { if (name.get(i) != another.name.get(i)) { return name.get(i) - another.name.get(i); } } return name.size() - another.name.size(); } else { return score - another.score; } } } static class Path { int to; int score; public Path(int to, int score) { this.to = to; this.score = score; } } }