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.util.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;



public class Main{
	
	// ArrayList<Integer> lis = new ArrayList<Integer>();
	// ArrayList<String> lis = new ArrayList<String>();
	// PriorityQueue<P> que = new PriorityQueue<P>();
	// PriorityQueue<Integer> que = new PriorityQueue<Integer>();
	//  Stack<Integer> stack = new Stack<Integer>();
	//HashMap<Long,Long> map = new HashMap<Long,Long>();
    //	static long sum=0;
	// 1000000007 (10^9+7)
	//static int mod = 1000000007;
	static long mod = 1000000007;
	//static int mod = 1000000009; ArrayList<Integer> l[]= new ArrayList[n];
    // static int dx[]={1,-1,0,0};
	// static int dy[]={0,0,1,-1};
	// //static int dx[]={1,-1,0,0,1,1,-1,-1};
    //static int dy[]={0,0,1,-1,1,-1,1,-1};
	
	//static Set<Integer> set = new HashSet<Integer>();
	//static ArrayList<Integer> l[];
    //static int parent[][],depth[],node,max_log;
	//static ArrayList<Integer> l[];

public  static void main(String[] args)   throws Exception, IOException{

	//Scanner sc =new Scanner(System.in);
	
	Reader sc = new Reader(System.in);
 	
 	int n=sc.nextInt(),m=sc.nextInt();
 	int g[][][]=graph_in(sc,n,m),pvds[][]=new int[n][2];
    int st=sc.nextInt()-1;

    int pr[]=dijkh(g,st,pvds);
    boolean u[]=new boolean[n];
	u[st]=true;
	long r=0;
	StringBuilder sb=new StringBuilder("");

	for( int i=0; i<n; i++ ){
		if(u[i])continue;
		int from=i;
		while(!u[from]){ u[from]=true; r+=pvds[from][0]; sb.append(pvds[from][1]); sb.append(" ");   from=pr[from]; }

	}

    //db(pr,pvds);

   System.out.println(r);
   System.out.println(sb);

//   System.out.println();


}


	
static int[][][]   graph_in(Reader sc,int n,int m) throws Exception, IOException{
   
    int r[][][]=new int[n][][]; //heavy edge
    //int r[][];  // edge 1
    //m=n-1 if tree	

    int pr[]=new int[m];
    int ch[]=new int[m];
    int ds[]=new int[m]; 
    int dg[]=new int[n];


    for (int i=0; i<m; i++) {
    	int a=sc.nextInt(),b=sc.nextInt(),d=sc.nextInt();
    	
    	a--;b--;

          pr[i]=a; ch[i]=b; ds[i]=d;
          dg[a]++;dg[b]++;
    }

for (int i=0; i<n; i++) r[i]=new int[dg[i]][3]; //child id and distance

    for (int i=0; i<m; i++) {

       int a=pr[i],b=ch[i],d=ds[i];

       r[ a ][dg[a]-1][0]=b;
       r[ a ][dg[a]-1][1]=d;
       r[ a ][--dg[a]][2]=i+1;


       r[ b ][dg[b]-1][0]=a;
       r[ b ][dg[b]-1][1]=d;
       r[ b ][--dg[b]][2]=i+1;

    }

    return r;

 }

    static int[] dijkh(int[][][] g, int from,int pvds[][])
     {
             int n = g.length;
             long[][] td = new long[2][n];
             

             Arrays.fill(td[0], 1L<<50 );

             int[] prev = new int[n];

             Arrays.fill(prev, -1);
             TreeSet<Integer> q = new TreeSet<Integer>(new Comparator<Integer>(){
                     public int compare(Integer a, Integer b) {
                             if(td[0][a] - td[0][b] != 0)return Long.signum(td[0][a] - td[0][b]);
                             return a-b;
                     }
             });
             q.add(from);
             td[0][from] = 0;

             while(q.size() > 0){
                     int cur = q.pollFirst();

                     for(int i = 0;i < g[cur].length;i++){
                             int next = g[cur][i][0];
                             long nd = td[0][cur] + g[cur][i][1];
                             if(nd <= td[0][next]){

                             	if(nd == td[0][next] && td[1][next]<=g[cur][i][1])continue;

                                     q.remove(next);
                                     td[0][next] = nd;
									 td[1][next] =g[cur][i][1];                                 
                                     
                                     prev[next] = cur;
                                     pvds[next][0] = g[cur][i][1];
                                     pvds[next][1] = g[cur][i][2];
                                     q.add(next);
                             }
                     }
             }

             return prev;
     }

static void db(Object... os){
    System.err.println(Arrays.deepToString(os));

}

static boolean validpos(int x,int y,int r, int c){
	
	return x<r && 0<=x && y<c && 0<=y;
	
}

static boolean bit(long x,int k){
	// weather k-th bit (from right) be one or zero
	return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
}


}



	

class Reader
{ 
	private BufferedReader x;
	private StringTokenizer st;
	
	public Reader(InputStream in)
	{
		x = new BufferedReader(new InputStreamReader(in));
		st = null;
	}
	public String nextString() throws IOException
	{
		while( st==null || !st.hasMoreTokens() )
			st = new StringTokenizer(x.readLine());
		return st.nextToken();
	}
	public int nextInt() throws IOException
	{
		return Integer.parseInt(nextString());
	}
	public long nextLong() throws IOException
	{
		return Long.parseLong(nextString());
	}
	public double nextDouble() throws IOException
	{
		return Double.parseDouble(nextString());
	}
}