#include <bits/stdc++.h>
using namespace std;
long long int INF = 1000000000000000000;
struct Edge {
  Edge() : u(INF), v(INF), id(INF), weight(INF) {}
  Edge(int u1, int v1, long long int w1, int id1)
      : u(u1), v(v1), weight(w1), id(id1) {}
  int u;
  int v;
  int id;
  long long int weight;
};
Edge def;
struct Item {
  long long int distance;
  Edge edge;
  int u;
  Item() : distance(INF), u(INF), edge(def) {}
  Item(long long int d, int u1, Edge e) : distance(d), u(u1), edge(e) {}
  bool operator<(const Item& item) const {
    return pair<long long int, long long int>(distance, edge.weight) >
           pair<long long int, long long int>(item.distance, item.edge.weight);
  }
};
vector<Edge> graph[300010];
Item dist[300010];
priority_queue<Item> pq;
int N, M;
int main() {
  cin >> N >> M;
  long long int u, v, w;
  for (int i = 0; i < M; i++) {
    cin >> u >> v >> w;
    graph[u].push_back(Edge(u, v, w, i + 1));
    graph[v].push_back(Edge(v, u, w, i + 1));
  }
  cin >> u;
  pq.push(Item(0, u, Edge()));
  dist[u] = Item(0, u, Edge());
  while (!pq.empty()) {
    Item item = pq.top();
    pq.pop();
    if (item < dist[item.u]) continue;
    for (auto edge : graph[item.u]) {
      Item newitem = Item(item.distance + edge.weight, edge.v, edge);
      if (dist[edge.v] < newitem) {
        dist[edge.v] = newitem;
        pq.push(newitem);
      }
    }
  }
  long long int sum = 0;
  vector<int> soln;
  for (int i = 1; i <= N; i++) {
    if (dist[i].distance != INF and i != u) {
      sum += dist[i].edge.weight;
      soln.push_back(dist[i].edge.id);
    }
  }
  cout << sum << endl;
  for (int i = 0; i < soln.size(); i++) {
    if (i != 0) cout << " ";
    cout << soln[i];
  }
  return 0;
}
