Problem: Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows.

Let's assume that we are given a connected weighted undirected graph G = (V, E) (here V is the set of vertices, E is the set of edges). The shortest-path tree from vertex u is such graph G1 = (V, E1) that is a tree with the set of edges E1 that is the subset of the set of edges of the initial graph E, and the lengths of the shortest paths from u to any vertex to G and to G1 are the same. 

You are given a connected weighted undirected graph G and vertex u. Your task is to find the shortest-path tree of the given graph from vertex u, the total weight of whose edges is minimum possible.

Input

The first line contains two numbers, n and m (1 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of vertices and edges of the graph, respectively.

Next m lines contain three integers each, representing an edge — ui, vi, wi — the numbers of vertices connected by an edge and the weight of the edge (ui ≠ vi, 1 ≤ wi ≤ 109). It is guaranteed that graph is connected and that there is no more than one edge between any pair of vertices.

The last line of the input contains integer u (1 ≤ u ≤ n) — the number of the start vertex.

Output

In the first line print the minimum total weight of the edges of the tree.

In the next line print the indices of the edges that are included in the tree, separated by spaces. The edges are numbered starting from 1 in the order they follow in the input. You may print the numbers of the edges in any order.

If there are multiple answers, print any of them.

Examples

Input

3 3
1 2 1
2 3 1
1 3 2
3


Output

2
1 2 


Input

4 4
1 2 1
2 3 1
3 4 1
4 1 2
4


Output

4
2 3 4 

Note

In the first sample there are two possible shortest path trees:

  * with edges 1 – 3 and 2 – 3 (the total weight is 3); 
  * with edges 1 – 2 and 2 – 3 (the total weight is 2); 



And, for example, a tree with edges 1 – 2 and 1 – 3 won't be a shortest path tree for vertex 3, because the distance from vertex 3 to vertex 2 in this tree equals 3, and in the original graph it is 1.

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Random;

public class P1 {
	private static final int mod = (int) 1e9 + 7;
	final Random random = new Random(0);
	final IOFast in = new IOFast();
	static PriorityQueue<Edge> pq;

	// / MAIN CODE
	public void run() throws IOException {
		// int TEST_CASE = Integer.parseInt(new String(in.nextLine()).trim());
		int TEST_CASE = 1;
		while (TEST_CASE-- != 0) {
			int n = in.nextInt();
			int m = in.nextInt();
			WeightedAdjListGraph g = new WeightedAdjListGraph(n, 2 * m);

			int a[] = new int[m];
			int b[] = new int[m];
			long cost[] = new long[m];
			for (int i = 0; i < m; i++) {
				int s = in.nextInt() - 1;
				int t = in.nextInt() - 1;
				int c = in.nextInt();
				g.addEdge(s, t, c);
				g.addEdge(t, s, c);
				a[i] = s;
				b[i] = t;
				cost[i] = c;

			}
			int S = in.nextInt() - 1;
			long[] d1 = g.dijkstra(S)[0];
			long ans = 0;
			pq = new PriorityQueue<Edge>();

			for (int i = 0; i < m; i++) {
				int ss = a[i];
				int tt = b[i];
				long cc = cost[i];
				if (d1[ss] + cc == d1[tt] || d1[tt] + cc == d1[ss])
					pq.add(new Edge(a[i], b[i], cc, i + 1, Math.max(d1[ss], d1[tt])));
			}

			DisjointSet ds = new DisjointSet(n);
			int an[] = new int[n - 1];
			int cnt = 0;
			while (!pq.isEmpty()) {
				Edge e = pq.poll();
				if (ds.findSet(e.v1) != ds.findSet(e.v2)) {
					ds.union(e.v1, e.v2);
					ans += e.weight;
					an[cnt] = e.i;
					cnt++;
				}
			}
			in.out.println(ans);

			for (int i = 0; i < cnt; i++) {
				in.out.print(an[i] + " ");
			}

		}
	}

	static class DisjointSet {
		int[] rank, parent, size;
		int n;

		DisjointSet(int n) {
			rank = new int[n];
			parent = new int[n];
			size = new int[n + 1];
			this.n = n;
			makeSet();
		}

		void makeSet() {

			for (int i = 0; i < n; i++) {
				parent[i] = i;
				rank[i] = 1;
			}
		}

		int findSet(int x) {
			if (parent[x] != x) {
				parent[x] = findSet(parent[x]);
				rank[x] = rank[parent[x]];
			}

			return parent[x];
		}

		int union(int x, int y) {
			int xRoot = findSet(x);
			int yRoot = findSet(y);
			if (xRoot == yRoot) {
				return rank[xRoot];
			}

			if (rank[xRoot] < rank[yRoot]) {
				parent[xRoot] = yRoot;
				rank[yRoot] += rank[xRoot];
				return rank[yRoot];
			}

			else if (rank[yRoot] < rank[xRoot]) {
				parent[yRoot] = xRoot;
				rank[xRoot] += rank[yRoot];

				return rank[xRoot];
			}

			else {
				parent[yRoot] = xRoot;
				rank[xRoot] = rank[xRoot] * 2;
				return rank[xRoot];
			}
		}

	}

	static class Edge implements Comparable<Edge> {
		public int v1, v2;
		long weight;
		int i;
		long val;

		Edge(int v1, int v2, long weight, int ii, long v) {
			this.v1 = v1;
			this.v2 = v2;
			this.weight = weight;
			i = ii;
			val = v;
		}

		public int other(int a) {
			if (a == v1)
				return v2;
			else
				return v1;
		}

		@Override
		public int compareTo(Edge edge) {
			if (edge.val == this.val)
				return Long.compare(this.weight, edge.weight);
			else {

				return Long.compare(this.val, edge.val);

			}

		}
	}

	static class WeightedAdjListGraph {
		int m, V, E;
		int[] head, next, cost, to;

		public WeightedAdjListGraph(int V, int E) {
			head = new int[V];
			next = new int[E];
			cost = new int[E];
			to = new int[E];
			this.V = V;
			this.E = E;
			clear();
		}

		public void clear() {
			m = 0;
			Arrays.fill(head, -1);
		}

		public void addEdge(int s, int t, int c) {
			next[m] = head[s];
			cost[m] = c;
			head[s] = m;
			to[m++] = t;
		}

		public int[][] bfs(final int src) {
			final int[] dist = new int[head.length];
			final int[] prev = new int[head.length];
			final int[] q = new int[2 * head.length + 10];
			int s = 0, t = 0;

			Arrays.fill(dist, -1);
			Arrays.fill(prev, -1);
			dist[src] = 0;
			q[t++] = src;
			while (s != t) {
				final int v = q[s++];
				for (int e = head[v]; e != -1; e = next[e]) {
					final int u = to[e];
					if (dist[u] == -1) {
						dist[u] = dist[v] + 1;
						prev[u] = v;
						q[t++] = u;
					}
				}
			}
			return new int[][] { dist, prev };
		}

		public long[][] dijkstra(final int s) {
			final long[] dist = new long[head.length];
			final long[] prev = new long[head.length];
			final PriorityQueue<long[]> q = new PriorityQueue<long[]>(10, new Comparator<long[]>() {
				@Override
				public int compare(long[] o1, long[] o2) {
					return Long.compare(o1[0], o2[0]);
				}
			});

			Arrays.fill(dist, Long.MAX_VALUE / 2);
			Arrays.fill(prev, -1);
			dist[s] = 0;
			q.add(new long[] { 0, s, });
			while (!q.isEmpty()) {
				final long[] xs = q.poll();
				final long v = xs[1];
				final long d = xs[0];
				if (dist[(int) v] < d)
					continue;

				for (int e = head[(int) v]; e != -1; e = next[e]) {
					final int t = to[e];
					final long w = d + cost[e];
					if (w < dist[t]) {
						dist[t] = w;
						prev[t] = v;
						q.add(new long[] { w, t, });
					}
				}
			}
			for (int i = 0; i < dist.length; i++) {
				if (dist[i] == Long.MAX_VALUE / 2) {
					dist[i] = -1;
				}
			}
			return new long[][] { dist, prev };
		}

		public static void main(String[] args) throws IOException {
			new P1().main();
		}
	}

	// / TEMPLATE
	static int gcd(int n, int r) {
		return r == 0 ? n : gcd(r, n % r);
	}

	static long gcd(long n, long r) {
		return r == 0 ? n : gcd(r, n % r);
	}

	static <T> void swap(T[] x, int i, int j) {
		T t = x[i];
		x[i] = x[j];
		x[j] = t;
	}

	static void swap(int[] x, int i, int j) {
		int t = x[i];
		x[i] = x[j];
		x[j] = t;
	}

	void main() throws IOException {
		// IOFast.setFileIO("rle-size.in", "rle-size.out");
		try {
			run();
		} catch (EndOfFileRuntimeException e) {
		}
		in.out.flush();
	}

	public static void main(String[] args) throws IOException {
		new P1().main();
	}

	static class EndOfFileRuntimeException extends RuntimeException {
		private static final long serialVersionUID = -8565341110209207657L;
	}

	static public class IOFast {
		private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		private PrintWriter out = new PrintWriter(System.out);

		void setFileIn(String ins) throws IOException {
			in.close();
			in = new BufferedReader(new FileReader(ins));
		}

		void setFileOut(String outs) throws IOException {
			out.flush();
			out.close();
			out = new PrintWriter(new FileWriter(outs));
		}

		void setFileIO(String ins, String outs) throws IOException {
			setFileIn(ins);
			setFileOut(outs);
		}

		private static int pos, readLen;
		private static final char[] buffer = new char[1024 * 8];
		private static char[] str = new char[500 * 8 * 2];
		private static boolean[] isDigit = new boolean[256];
		private static boolean[] isSpace = new boolean[256];
		private static boolean[] isLineSep = new boolean[256];

		static {
			for (int i = 0; i < 10; i++) {
				isDigit['0' + i] = true;
			}
			isDigit['-'] = true;
			isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
			isLineSep['\r'] = isLineSep['\n'] = true;
		}

		public int read() throws IOException {
			if (pos >= readLen) {
				pos = 0;
				readLen = in.read(buffer);
				if (readLen <= 0) {
					throw new EndOfFileRuntimeException();
				}
			}
			return buffer[pos++];
		}

		public int nextInt() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(len, isSpace);
			int i = 0;
			int ret = 0;
			if (str[0] == '-') {
				i = 1;
			}
			for (; i < len; i++)
				ret = ret * 10 + str[i] - '0';
			if (str[0] == '-') {
				ret = -ret;
			}
			return ret;
		}

		public long nextLong() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(len, isSpace);
			int i = 0;
			long ret = 0;
			if (str[0] == '-') {
				i = 1;
			}
			for (; i < len; i++)
				ret = ret * 10 + str[i] - '0';
			if (str[0] == '-') {
				ret = -ret;
			}
			return ret;
		}

		public char nextChar() throws IOException {
			while (true) {
				final int c = read();
				if (!isSpace[c]) {
					return (char) c;
				}
			}
		}

		int reads(int len, boolean[] accept) throws IOException {
			try {
				while (true) {
					final int c = read();
					if (accept[c]) {
						break;
					}
					if (str.length == len) {
						char[] rep = new char[str.length * 3 / 2];
						System.arraycopy(str, 0, rep, 0, str.length);
						str = rep;
					}
					str[len++] = (char) c;
				}
			} catch (EndOfFileRuntimeException e) {
				;
			}
			return len;
		}

		int reads(char[] cs, int len, boolean[] accept) throws IOException {
			try {
				while (true) {
					final int c = read();
					if (accept[c]) {
						break;
					}
					cs[len++] = (char) c;
				}
			} catch (EndOfFileRuntimeException e) {
				;
			}
			return len;
		}

		public char[] nextLine() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(len, isLineSep);
			try {
				if (str[len - 1] == '\r') {
					len--;
					read();
				}
			} catch (EndOfFileRuntimeException e) {
				;
			}
			return Arrays.copyOf(str, len);
		}

		public String nextString() throws IOException {
			return new String(next());
		}

		public char[] next() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(len, isSpace);
			return Arrays.copyOf(str, len);
		}

		public int next(char[] cs) throws IOException {
			int len = 0;
			cs[len++] = nextChar();
			len = reads(cs, len, isSpace);
			return len;
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(nextString());
		}

		public long[] nextLongArray(final int n) throws IOException {
			final long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public int[] nextIntArray(final int n) throws IOException {
			final int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[][] nextIntArray2D(final int n, final int k) throws IOException {
			final int[][] res = new int[n][];
			for (int i = 0; i < n; i++) {
				res[i] = nextIntArray(k);
			}
			return res;
		}

		public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException {
			final int[][] res = new int[n][k + 1];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < k; j++) {
					res[i][j] = nextInt();
				}
				res[i][k] = i;
			}
			return res;
		}

		public double[] nextDoubleArray(final int n) throws IOException {
			final double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}
	}
}