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.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashMap;
import java.util.PriorityQueue;

public class CF2_303E {

  static long[] distanceTo;
  static long[] lenTo;
  static Edge[] edgeTo;
  static final long INF = Long.MAX_VALUE / 2L;
  static HashMap<Edge, Integer> map;
  static boolean[] used;

  static Reader sc = new Reader();
  static PrintWriter out = new PrintWriter(System.out);

  public static void main(String[] args) throws IOException {
    int n = sc.nextInt();
    int numEdges = sc.nextInt();
    
    GraphWE graph = new GraphWE(n);
    map = new HashMap<Edge, Integer>();
    Edge[] edges = new Edge[numEdges];
    
    for (int i = 0; i < numEdges; i++) {
      int[] aux = {sc.nextInt() - 1, sc.nextInt() - 1};
      Arrays.sort(aux);
      edges[i] = new Edge(aux[0], aux[1], sc.nextLong());
      
      map.put(edges[i], i);
      
      graph.addUEdge(edges[i]);
    }
    int source = sc.nextInt() - 1;
    
    dijkstra(graph, source);
    
    used = new boolean[numEdges];
    
    for (int i = 0; i < n; i++) {
      pathTo(i);
    }
    
    long cc = 0;
    for (int i = 0; i < numEdges; i++) {
      if (used[i]) {
        cc += edges[i].weight;
      }
    }
    
    out.println(cc);
    int count = 0;
    for (int i = 0; i < numEdges; i++) {
      if(count != 0) {
        out.print(" ");
      }
      if (used[i]) {
        out.print(i+1);
        count++;
      }
    }
    
    out.println();
    out.close();
  }

  static void pathTo(int dest) {
    //ArrayDeque<Edge> path = new ArrayDeque<Edge>();
    if (distanceTo[dest] == INF) {
      return;
    }

    for (Edge edge = edgeTo[dest]; edge != null; edge = edgeTo[edge.from]) {
      //path.addFirst(edge);
      int[] aux = {edge.from, edge.to};
      Arrays.sort(aux);
      Edge curEdge = new Edge(aux[0], aux[1], edge.weight);
      int ind = map.get(curEdge);
      if (used[ind]) {
        break;
      } else {
        used[ind] = true;
      }
    }
    return;
  }
  
  static void dijkstra(GraphWE graph, int source) {
    dijkstra(graph, source, -1);
  }

  /**
   * Performance guaranteed only with non-negative edges.
   * 
   * @time O(|E| log |V|)
   * @tested UVA_10986, UVA_11367
   */
  static void dijkstra(GraphWE graph, int source, int dest) {
    edgeTo = new Edge[graph.getNumVertices()];
    distanceTo = new long[graph.getNumVertices()];
    lenTo = new long[graph.getNumVertices()];
    Arrays.fill(distanceTo, INF);
    PriorityQueue<Triple<Long, Long, Integer>> queue = new PriorityQueue<Triple<Long, Long, Integer>>();
    distanceTo[source] = 0;

    queue.add(new Triple<Long, Long,Integer>(0L, 0L, source));

    while (!queue.isEmpty()) {
      Triple<Long, Long, Integer> elem = queue.poll();
      int cur = elem.third;
      long len = elem.second;
      
      if (cur == dest) {
        break;
      }
      
      if (elem.first > distanceTo[cur]) {
        continue;
      }
      
      
      for (Edge edge : graph.adj(cur)) {
        if (distanceTo[edge.to] > distanceTo[edge.from] + edge.weight 
                || (distanceTo[edge.to] == distanceTo[edge.from] + edge.weight && edge.weight < edgeTo[edge.to].weight)) {
          distanceTo[edge.to] = distanceTo[edge.from] + edge.weight;
          edgeTo[edge.to] = edge;
          lenTo[edge.to] =  len + 1L;
          queue.add(new Triple<Long, Long, Integer>(distanceTo[edge.to], len + 1L, edge.to));
        }
      }
    }
  }


/**
 * @author Juan Martínez (https://www.linkedin.com/in/martinezgjuan)
 * @tested FBHC2015_Qual3, UVA_11367
 */
public static class Triple<U extends Comparable<U>, V extends Comparable<V>, W extends Comparable<W>>
        implements Comparable<Triple<U, V, W>> {
  public final U first;
  public final V second;
  public final W third;

  public Triple(U first, V second, W third) {
    this.first = first;
    this.second = second;
    this.third = third;
  }

  public int compareTo(Triple<U, V, W> that) {
    int value = this.first.compareTo(that.first);
    if (value != 0)
      return value;
    value = this.second.compareTo(that.second);
    if (value != 0)
      return -value;
    return this.third.compareTo(that.third);
  }

  @Override
  public boolean equals(Object other) {
    if (!(other instanceof Triple)) {
      return false;
    }
    Triple that = (Triple<U, V, W>) other;
    return this.first.equals(that.first) && this.second.equals(that.second)
            && this.third.equals(that.third);
  }

  @Override
  public int hashCode() {
    return 31 * (31 * (527 + first.hashCode()) + second.hashCode()) + third.hashCode();
  }

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


  public static  class Pair<U extends Comparable<U>, V extends Comparable<V>> implements
          Comparable<Pair<U, V>> {
    public final U first;
    public final V second;

    public Pair(U first, V second) {
      this.first = first;
      this.second = second;
    }

    public int compareTo(Pair<U, V> that) {
      int value = this.first.compareTo(that.first);
      if (value != 0)
        return value;
      return this.second.compareTo(that.second);
    }

    @Override
    public boolean equals(Object other) {
      if (!(other instanceof Pair)) {
        return false;
      }
      Pair that = (Pair<U, V>) other;
      return this.first == that.first && this.second == that.second;
    }

    @Override
    public int hashCode() {
      return 31 * (527 + first.hashCode()) + second.hashCode();
    }

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

  static class GraphWE {
    private final int numVertices;
    private int numEdges = 0;
    private ArrayDeque<Edge>[] adj;

    @SuppressWarnings("unchecked")
    public GraphWE(int numVertices) {
      this.numVertices = numVertices;
      adj = (ArrayDeque<Edge>[]) new ArrayDeque[numVertices];
      for (int v = 0; v < numVertices; v++) {
        adj[v] = new ArrayDeque<Edge>();
      }
    }

    @SuppressWarnings("unchecked")
    public GraphWE(int numVertices, Iterable<Edge> edges) {
      this.numVertices = numVertices;
      adj = (ArrayDeque<Edge>[]) new ArrayDeque[numVertices];
      for (int v = 0; v < numVertices; v++) {
        adj[v] = new ArrayDeque<Edge>();
      }
      for (Edge edge : edges)
        addUEdge(edge);
    }

    public int getNumVertices() {
      return numVertices;
    }

    public int getNumEdges() {
      return numEdges;
    }

    public void addDEdge(Edge e) {
      adj[e.from].add(e);
      numEdges++;
    }

    public void addDEdge(int from, int to, int weight) {
      adj[from].add(new Edge(from, to, weight));
      numEdges++;
    }

    public void addUEdge(Edge edge) {
      adj[edge.from].add(edge);
      adj[edge.to].add(new Edge(edge.to, edge.from, edge.weight));
      numEdges++;
    }

    public void addUEdge(int from, int to, long l) {
      adj[from].add(new Edge(from, to, l));
      adj[to].add(new Edge(to, from, l));
      numEdges++;
    }

    public ArrayDeque<Edge> adj(int node) {
      return adj[node];
    }

    public String toString() {
      StringBuilder result = new StringBuilder(numVertices + numEdges);
      result.append("Nodes: " + numVertices + " Edges: " + numEdges + "\n");
      for (int act = 0; act < numVertices; act++) {
        result.append(act + " -> ");
        int count = 0;
        for (Edge e : adj(act)) {
          if (count != 0)
            result.append(", ");
          result.append("(" + e.to + " <" + e.weight + ">)");
          count++;
        }
        result.append('\n');
      }
      return result.toString();
    }
  }

  static class Edge implements Comparable<Edge> {
    public final int from, to;
    public long weight;

    Edge(int from, int to, long l) {
      this.from = from;
      this.to = to;
      this.weight = l;
    }

    Edge(int from, int to) {
      this.from = from;
      this.to = to;
      this.weight = 1;
    }

    @Override
    public boolean equals(Object other) {
      Edge that = (Edge) other;
      return this.from == that.from && this.to == that.to;
    }
    
    @Override
    public int hashCode() {
      return 31 * (527 + from) + to;
    }
        
    public int compareTo(Edge that) {
      if (Math.abs(this.weight - that.weight) > 0)
        return Long.compare(this.weight, that.weight);
      if (this.from == that.from)
        return Integer.compare(this.to, that.to);
      return Integer.compare(this.from, that.from);
    }

    public String toString() {
      return "(" + from + ", " + to + ", <" + weight + ">)";
    }
  }
  
  static class Reader {
    final private int BUFFER_SIZE = 1 << 12; private byte[] buffer; private int bufferPointer, bytesRead; private boolean eof = false;
    public Reader() {buffer = new byte[BUFFER_SIZE];bufferPointer = bytesRead = 0;}
    public boolean reachedEOF() {return eof;}
    private void fillBuffer() throws IOException {bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1;eof = true;}}
    private byte read() throws IOException {if (bufferPointer == bytesRead)fillBuffer();return buffer[bufferPointer++];}
    public String next() throws IOException {StringBuilder sb = new StringBuilder();byte c;while ((c = read()) <= ' ') {if (c == -1)return null;} do {sb.append((char) c);} while ((c = read()) > ' ');if (sb.length() == 0)return null;return sb.toString();}
    public String nextLine() throws IOException {StringBuilder sb = new StringBuilder();byte c;boolean read = false;while ((c = read()) != -1) {if (c == '\n') {read = true;break;}if (c >= ' ')sb.append((char) c);}if (!read)return null;return sb.toString();}
    public int nextInt() throws IOException {int ret = 0;byte c = read();while (c <= ' ')c = read();boolean neg = (c == '-');if (neg)c = read();do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (neg)return -ret;return ret;}
    public long nextLong() throws IOException {long ret = 0;byte c = read();while (c <= ' ')c = read();boolean neg = (c == '-');if (neg)c = read();do {ret = ret * 10L + c - '0';} while ((c = read()) >= '0' && c <= '9');if (neg)return -ret;return ret;}
    public double nextDouble() throws IOException {double ret = 0, div = 1;byte c = read();while (c <= ' ')c = read();boolean neg = (c == '-');if (neg)c = read();do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (c == '.')while ((c = read()) >= '0' && c <= '9')ret += (c - '0') / (div *= 10);if (neg)return -ret;return ret;}
    public int[] nextIntArray(int n) throws IOException {int[] a = new int[n];for (int i = 0; i < n; i++)a[i] = nextInt();return a;}
    public int[][] nextIntMatrix(int n, int m) throws IOException {int[][] map = new int[n][m];for (int i = 0; i < n; i++)map[i] = nextIntArray(m);return map;}
    public char[][] nextCharacterMatrix(int n) throws IOException {char[][] a = new char[n][];for (int i = 0; i < n; i++)a[i] = next().toCharArray();return a;}
    public void close() throws IOException {if (System.in == null)return;System.in.close();}
  }
  
  static void print(int[] A) {for(int i=0;i<A.length;i++){if(i!=0) out.print(' ');out.print(A[i]);}out.println();}
  static <T> void print(Iterable<T> A) {int i = 0;for(T act : A){if(i!=0)out.print(' ');out.print(act);i++;}out.println();}
  static void printPlus1(Iterable<Number> A) {int i = 0;for(Number act : A){if(i!=0)out.print(' ');out.print(act.longValue() + 1L);i++;}out.println();}
  static void debug(Object... o) { System.err.println(Arrays.deepToString(o)); }
  
  /*
    long s = System.currentTimeMillis();
    debug(System.currentTimeMillis()-s+"ms");
   */
}