import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int start = sc.nextInt(); int goal = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new TreeMap<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); graph.get(a).put(b, c); graph.get(b).put(a, c); } PriorityQueue queue = new PriorityQueue<>(); queue.add(new Path(goal, 0)); int[] costs = new int[n]; Arrays.fill(costs, Integer.MAX_VALUE / 2); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (Map.Entry entry : graph.get(p.idx).entrySet()) { queue.add(new Path(entry.getKey(), p.value + entry.getValue())); } } int current = start; int total = 0; ArrayList ans = new ArrayList<>(); ans.add(start); while (current != goal) { for (Map.Entry entry : graph.get(current).entrySet()) { if (costs[entry.getKey()] + total + entry.getValue() == costs[start]) { total += entry.getValue(); current = entry.getKey(); ans.add(current); break; } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < ans.size(); i++) { if (i > 0) { sb.append(" "); } sb.append(ans.get(i)); } System.out.println(sb); } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }