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.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class E {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Graph graph = Graph.readGraph(sc);
        int u = sc.nextInt();
        solve(graph, u);
    }

    private static void solve(Graph graph, int u) {
        Result dijkstra = graph.dijkstra(u - 1);
        int[] pathEdgeId = dijkstra.getPathEdgeId();
        int[] path = dijkstra.getPath();
        Set<Integer> edges = new TreeSet<>();
        long totalWeight = 0;
        int[] edgesWeightById = graph.getEdgesWeightById();
        int countNonReachable = 0;
        for (int i = 0; i < graph.getNodesCount(); i++) {
            int id = pathEdgeId[i];
            if (id != -1) {
                if (!edges.contains(id)) {
                    edges.add(id);
                    totalWeight += edgesWeightById[id];
                }
            }  else {
                countNonReachable++;
            }
        }
        if(edges.size() != graph.getNodesCount() - 1) {
            throw new RuntimeException("Wrong edges count in result tree: " + edges.size() + ", countNonReachable=" + countNonReachable);
        }
        System.out.println(totalWeight);
        StringBuilder sb = new StringBuilder();
        for (Integer edge : edges) {
            sb.append(edge + 1).append(" ");
        }
        System.out.println(sb.toString().trim());

    }
}

class Graph {
    private int nodesCount;
    private int edgesCount;
    private Vertex[] nodes;
    private VertexState visited[];
    private int time;
    private int currentEdgeId;
    private int edgesWeightById[];

    public static Graph readGraph(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        Graph graph = new Graph(n, m);
        for (int i = 0; i < m; i++) {
            int u = sc.nextInt();
            int v = sc.nextInt();
            int w = sc.nextInt();
            graph.addEdge(u - 1, v - 1, w);
        }
        return graph;
    }

    Graph(int nodesCount, int edgesCount) {
        this.nodesCount = nodesCount;
        nodes = new Vertex[nodesCount];
        visited = new VertexState[nodesCount];
        for (int i = 0; i < nodes.length; i++) {
            nodes[i] = new Vertex();
            visited[i] = new VertexState();
        }
        edgesWeightById = new int[edgesCount + 1];
    }

    public int getNodesCount() {
        return nodesCount;
    }

    public int getEdgesCount() {
        return edgesCount;
    }

    public void addEdge(int u, int v) {
        addEdge(u, v, 0);
    }

    public void addEdge(int u, int v, int cost) {
        addEdge(u, v, cost, Integer.MAX_VALUE / 2);
    }

    public void addEdge(int u, int v, int cost, int capacity) {
        nodes[u].addEdge(new Edge(v, cost, capacity, currentEdgeId));
        nodes[v].addEdge(new Edge(u, cost, capacity, currentEdgeId));
        edgesWeightById[currentEdgeId] = cost;
        currentEdgeId++;
        edgesCount++;
    }


    public List<Edge> getEdges(int id) {
        return nodes[id].getEdges();
    }

    public boolean isAllVertexVisited() {
        for (VertexState aVisited : visited) {
            if (aVisited.getColor() != VertexState.Color.BLACK) {
                // graph is not connected
                return false;
            }
        }
        return true;

    }

    public void clearVertexState() {
        for (int i = 0; i < nodes.length; i++) {
            visited[i] = new VertexState();
        }
        time = 0;
    }

    public VertexState[] getVertexStates() {
        return visited;
    }

    public VertexState getVertexState(int i) {
        return visited[i];
    }

    public void setColor(int i, VertexState.Color color) {
        visited[i].setColor(color);
        if (VertexState.Color.BLACK == color) {
            visited[i].setFinishTime(time++);
        } else if (VertexState.Color.GRAY == color) {
            visited[i].setDiscoverTime(time++);
        }
    }

    public VertexState.Color getColor(int i) {
        return visited[i].getColor();
    }

    public int getDiscoveryTime(int i) {
        return visited[i].getDiscoverTime();
    }

    public int getFinishTime(int i) {
        return visited[i].getFinishTime();
    }

    public int[] getEdgesWeightById() {
        return edgesWeightById;
    }

    // dijkstra search
    public Result dijkstra(int start) {
        long distance[] = new long[getNodesCount() + 1];
        int path[] = new int[getNodesCount() + 1];
        int pathEdgeId[] = new int[getNodesCount() + 1];
        Arrays.fill(distance, Long.MAX_VALUE);
        Arrays.fill(path, -1);
        Arrays.fill(pathEdgeId, -1);
        distance[start] = 0;

        PriorityQueue<SearchNode> nodesToVisit = new PriorityQueue<>();
        nodesToVisit.add(new SearchNode(start, 0, -1));

        while (!nodesToVisit.isEmpty()) {
            SearchNode searchNode = nodesToVisit.poll();
            long distToCurrent = distance[searchNode.getVertex()];
            if (distToCurrent == Integer.MAX_VALUE) {
                // graph is not connected
                throw new RuntimeException("Graph is not connected. No path between: " + start + " and " + searchNode.getVertex());
            }

            for (Edge edge : getEdges(searchNode.getVertex())) {
                long newDist = distToCurrent + edge.getWeight();
                if (distance[edge.getVertex()] > newDist ||
                        (distance[edge.getVertex()] == newDist && edgesWeightById[pathEdgeId[edge.getVertex()]] > edge.getWeight())) {
                    distance[edge.getVertex()] = newDist;
                    path[edge.getVertex()] = searchNode.getVertex();
                    pathEdgeId[edge.getVertex()] = edge.getId();
                    // update node with edge.vertex in priority queue
                    nodesToVisit.offer(new SearchNode(edge.getVertex(), newDist, edge.getId()));
                }
            }

        }
        return new Result(distance, path, pathEdgeId);
    }

}

class Vertex {
    private List<Edge> list = new ArrayList<>();

    public void addEdge(Edge edge) {
        list.add(edge);
    }

    public List<Edge> getEdges() {
        return list;
    }
}

class Edge {
    private int vertex;
    private int weight;
    private int capacity;
    private int id;

    Edge(int vertex) {
        this.vertex = vertex;
    }

    Edge(int vertex, int weight) {
        this.vertex = vertex;
        this.weight = weight;
    }

    Edge(int vertex, int weight, int capacity, int id) {
        this.vertex = vertex;
        this.weight = weight;
        this.capacity = capacity;
        this.id = id;
    }

    public int getVertex() {
        return vertex;
    }

    public int getWeight() {
        return weight;
    }

    public int getCapacity() {
        return capacity;
    }

    public int getId() {
        return id;
    }

    public void incCapacity() {
        capacity++;
    }

    public void decCapacity() {
        capacity--;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Edge)) return false;

        Edge edge = (Edge) o;

        if (vertex != edge.vertex) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return vertex;
    }

    @Override
    public String toString() {
        return "Edge{" +
                "vertex=" + vertex +
                ", weight=" + weight +
                '}';
    }
}

class SearchNode implements Comparable<SearchNode> {
    private int vertex;
    private long distance;
    private int edgeId;

    public SearchNode(int vertex, long distance, int edgeId) {
        this.vertex = vertex;
        this.distance = distance;
        this.edgeId = edgeId;
    }

    public int getVertex() {
        return vertex;
    }

    public long getDistance() {
        return distance;
    }

    public int getEdgeId() {
        return edgeId;
    }

    @Override
    public int compareTo(SearchNode o) {
        return Long.compare(distance, o.distance);
    }
}

class VertexState {
    public enum Color {
        BLACK, GRAY, WHITE
    }

    private Color color;
    private int discoverTime;
    private int finishTime;

    VertexState() {
        color = Color.WHITE;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public int getDiscoverTime() {
        return discoverTime;
    }

    public void setDiscoverTime(int discoverTime) {
        this.discoverTime = discoverTime;
    }

    public int getFinishTime() {
        return finishTime;
    }

    public void setFinishTime(int finishTime) {
        this.finishTime = finishTime;
    }
}

class Result {

    private final long[] distance;
    private final int[] path;
    private final int[] pathEdgeId;

    public Result(long[] distance, int[] path, int[] pathEdgeId) {
        this.distance = distance;
        this.path = path;
        this.pathEdgeId = pathEdgeId;
    }

    public long[] getDistance() {
        return distance;
    }

    public int[] getPath() {
        return path;
    }

    public int[] getPathEdgeId() {
        return pathEdgeId;
    }
}