import java.io.*; import java.util.*; public class Main_yukicoder160 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int m = sc.nextInt(); int s = sc.nextInt(); int g = sc.nextInt(); Dijkstra di = new Dijkstra(n); for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); di.addEdge(a, b, c); di.addEdge(b, a, c); } // pr.println(di.getShortestPath(g, s)); int[] path = di.getPath(g, s); List ret = new ArrayList<>(); ret.add(s); while (path[s] != -1) { ret.add(path[s]); s = path[s]; } for (int i = 0; i < ret.size(); i++) { pr.print(ret.get(i)); if (i < ret.size() - 1) { pr.print(" "); } } pr.println(); pr.close(); sc.close(); } private static class Dijkstra { long[] d; List[] edges; PriorityQueue pq; int n; int s; int[] prev; final long INF = Long.MAX_VALUE; @SuppressWarnings("unchecked") Dijkstra(int n) { this.n = n; edges = new List[n]; for (int ii = 0; ii < n; ii++) { edges[ii] = new ArrayList(); } s = - 1; } // i, j:0-indexed public void addEdge(int i, int j, int c) { edges[i].add(new Edge(i, j, c)); } public long getShortestPath(int i, int j) { if (s != i) { d = new long[n]; Arrays.fill(d, INF); d[i] = 0; prev = new int[n]; Arrays.fill(prev, -1); pq = new PriorityQueue(); pq.add(new Vertex(i, d[i])); while (!pq.isEmpty()) { Vertex u = pq.poll(); if (d[u.me] < u.d) { continue; // skip old vertex } for (int ii = 0; ii < edges[u.me].size(); ii++) { Edge v = edges[u.me].get(ii); if (d[u.me] != INF && d[v.v] > d[u.me] + v.w) { d[v.v] = d[u.me] + v.w; pq.add(new Vertex(v.v, d[v.v])); prev[v.v] = u.me; } else if (d[u.me] != INF && d[v.v] == d[u.me] + v.w && prev[v.v] > u.me) { pq.add(new Vertex(v.v, d[v.v])); prev[v.v] = u.me; } } } s = i; } return d[j]; } public int[] getPath(int i, int j) { if (s != i) { getShortestPath(i, j); } return prev; } private static class Edge { // int u; // from int v; // to int w; // cost Edge(int u, int v, int w) { // this.u = u; this.v = v; this.w = w; } } private static class Vertex implements Comparable { int me; // me long d; // cost Vertex(int u, long w) { this.me = u; this.d = w; } @Override public int compareTo(Vertex o) { return Long.compare(this.d, o.d); // return this.d > o.d ? 1 : this.d < o.d ? -1 : 0; } } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }