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.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.math.BigDecimal;
import java.util.List;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.OutputStream;
import java.util.Collections;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator;
import java.io.IOException;
import java.util.Arrays;
import java.util.AbstractList;
import java.io.InputStream;
import java.util.Locale;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.AbstractCollection;
import java.util.RandomAccess;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int vertexCount = in.nextInt();
        int edgeCount = in.nextInt();
        int[] from = new int[edgeCount];
        int[] to = new int[edgeCount];
        long[] weight = new long[edgeCount];
        ArrayUtils.readGraphArrays(in, from, to, weight);
        ArrayUtils.decreaseByOne(from, to);
        Graph graph = new BidirectionalFixedWeightedGraph(vertexCount, from, to, weight);
        int startVertex = in.nextInt() - 1;
        long[] distance = GraphAlgorithms.heapDijkstra(graph, startVertex);
        long[] toWeight = new long[vertexCount];
        Arrays.fill(toWeight, Long.MAX_VALUE);
        int[] toIndex = new int[vertexCount];
        for (int i = 0; i < edgeCount; i++) {
            if (Math.abs(distance[from[i]] - distance[to[i]]) == weight[i]) {
                if (distance[from[i]] > distance[to[i]]) {
                    if (toWeight[from[i]] > weight[i]) {
                        toWeight[from[i]] = weight[i];
                        toIndex[from[i]] = i + 1;
                    }
                } else {
                    if (toWeight[to[i]] > weight[i]) {
                        toWeight[to[i]] = weight[i];
                        toIndex[to[i]] = i + 1;
                    }
                }
            }
        }
        long answer = 0;
        boolean[] appear = new boolean[vertexCount];
        appear[startVertex] = true;
        for (int i = 0; i < edgeCount; i++) {
            appear[from[i]] = true;
            appear[to[i]] = true;
        }
        int count = 0;
        for (boolean b : appear) {
            if (b)
                count++;
        }
        if (count != vertexCount) {
            throw new RuntimeException(String.valueOf(count));
        }
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < vertexCount; i++) {
            if (i != startVertex) {
                if (toIndex[i] == 0) {
                    System.out.println("i = " + i);
                    System.out.println("distance[i] = " + distance[i]);
                    System.out.println("appear[i] = " + appear[i]);
                    for (int j = 0; j < edgeCount; j++) {
                        if ((from[j] == i || to[j] == i) && 1 == weight[j]) {
                            System.out.println(from[j] + " " + to[j] + " " + distance[from[j]] + " " + distance[to[j]]);
                        }
                    }
                }
                result.add(toIndex[i]);
                answer += toWeight[i];
            }
        }
        out.println(answer);
        Collections.sort(result);
        out.printLine(result.toArray());
    }


}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

}

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public void println(long x) {
        writer.println(x);
    }

    public void print(Object obj) {
        writer.print(obj);
    }

    public void println() {
        writer.println();
    }

    public void print(char c) {
        writer.print(c);
    }

    public void close() {
        writer.close();
    }

    public void printItems(Object... items) {
        for (int i = 0; i < items.length; i++) {
            if (i != 0) {
                print(' ');
            }
            print(items[i]);
        }
    }

    public void printLine(Object... items) {
        printItems(items);
        println();
    }

}

class ArrayUtils {


    public static void readGraphArrays(InputReader in, int[] from, int[] to, long[] weight) {
        for (int i = 0; i < from.length; i++) {
            from[i] = in.nextInt();
            to[i] = in.nextInt();
            weight[i] = in.nextLong();
        }
    }

    public static void decreaseByOne(int[]... arrays) {
        for (int[] array : arrays) {
            for (int i = 0; i < array.length; i++) {
                array[i]--;
            }
        }
    }


}

interface Graph {
    int getVertexCount();

    Iterable<Edge> getConnectedEdges(int vertexNo);
}

class BidirectionalFixedWeightedGraph extends FixedWeightedGraph {
    public BidirectionalFixedWeightedGraph(int vertexCount, int[] from, int[] to, long[] weight) {
        if (from.length != to.length || from.length != weight.length) {
            throw new IllegalArgumentException();
        }
        edges = new int[vertexCount][];
        this.weight = new long[vertexCount][];
        int[] degree = new int[vertexCount];
        for (int i = 0; i < from.length; i++) {
            degree[from[i]]++;
            degree[to[i]]++;
        }
        for (int i = 0; i < vertexCount; i++) {
            edges[i] = new int[degree[i]];
            this.weight[i] = new long[degree[i]];
        }
        for (int i = 0; i < from.length; i++) {
            degree[from[i]]--;
            edges[from[i]][degree[from[i]]] = to[i];
            this.weight[from[i]][degree[from[i]]] = weight[i];
            degree[to[i]]--;
            edges[to[i]][degree[to[i]]] = from[i];
            this.weight[to[i]][degree[to[i]]] = weight[i];
        }
    }
}

class GraphAlgorithms {
    public static final long INF = Long.MAX_VALUE / 4;
    public static long[] heapDijkstra(Graph graph, int startVertex) {
        int vertexCount = graph.getVertexCount();
        final long[] distance = new long[vertexCount];
        boolean[] done = new boolean[vertexCount];
        Arrays.fill(distance, INF);
        distance[startVertex] = 0;
        PriorityQueue<Pair<Long, Integer>> queue = new PriorityQueue<Pair<Long, Integer>>(vertexCount);
        queue.add(Pair.makePair(distance[startVertex], startVertex));
        while (!queue.isEmpty()) {
            int currentVertex = queue.poll().second;
            if (done[currentVertex]) {
                continue;
            }
            done[currentVertex] = true;
            for (Edge edge : graph.getConnectedEdges(currentVertex)) {
                if (distance[edge.getDestination()] > distance[currentVertex] + edge.getWeight()) {
                    distance[edge.getDestination()] = distance[currentVertex] + edge.getWeight();
                    queue.add(Pair.makePair(distance[edge.getDestination()], edge.getDestination()));
                }
            }
        }
        return distance;
    }

}

interface Edge {
    public int getDestination();
    public long getWeight();
}

abstract class FixedWeightedGraph extends FixedGraph {
    protected long[][] weight;

    protected Iterator<Edge> getConnectedEdgesIterator(final int vertexNo) {
        return new Iterator<Edge>() {
            int current = 0;

            public boolean hasNext() {
                return current < edges[vertexNo].length;
            }

            public Edge next() {
                if (!hasNext())
                    throw new NoSuchElementException();
                current++;
                return new WeightedEdge(vertexNo, edges[vertexNo][current - 1], weight[vertexNo][current - 1]);
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
}

class Pair<A,B> implements Comparable<Pair<A, B>> {
    public final A first;
    public final B second;

    public Pair(A first, B second) {
        this.first = first;
        this.second = second;
    }

    public static <A, B> Pair<A, B> makePair(A first, B second) {
        return new Pair<A, B>(first, second);
    }

    public int compareTo(Pair<A, B> anotherPair) {
        //noinspection unchecked
        int result = ((Comparable<A>)first).compareTo(anotherPair.first);
        if (result != 0) {
            return result;
        }
        //noinspection unchecked
        return ((Comparable<B>)second).compareTo(anotherPair.second);
    }


    public String toString() {
        return "(" + first + ", " + second + ")";
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Pair pair = (Pair) o;

        if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
        if (second != null ? !second.equals(pair.second) : pair.second != null) return false;

        return true;
    }

    public int hashCode() {
        int result = first != null ? first.hashCode() : 0;
        result = 31 * result + (second != null ? second.hashCode() : 0);
        return result;
    }
}

abstract class FixedGraph implements Graph {
    protected int[][] edges;

    public int getVertexCount() {
        return edges.length;
    }

    public Iterable<Edge> getConnectedEdges(final int vertexNo) {
        return new Iterable<Edge>() {
            public Iterator<Edge> iterator() {
                return getConnectedEdgesIterator(vertexNo);
            }
        };
    }

    protected Iterator<Edge> getConnectedEdgesIterator(final int vertexNo) {
        return new Iterator<Edge>() {
            int current = 0;
            public boolean hasNext() {
                return current < edges[vertexNo].length;
            }

            public Edge next() {
                if (!hasNext())
                    throw new NoSuchElementException();
                return new SimpleEdge(vertexNo, edges[vertexNo][current++]);
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
}

class WeightedEdge extends SimpleEdge {
    protected long weight;

    public WeightedEdge(int source, int destination, long weight) {
        super(source, destination);
        this.weight = weight;
    }

    public long getWeight() {
        return weight;
    }

    public String toString() {
        return "(" + source + "->" + destination + ": " + weight + ")";
    }

}

class SimpleEdge implements Edge {
    protected int source, destination;

    public SimpleEdge(int source, int destination) {
        this.source = source;
        this.destination = destination;
    }

    public int getDestination() {
        return destination;
    }

    public long getWeight() {
        return 1;
    }

    public String toString() {
        return "(" + source + "->" + destination + ")";
    }
}