#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int src, dest;
  long long int cost;
} node;
node create_node(int a, int b, long long int c) {
  node ret;
  ret.src = a;
  ret.dest = b;
  ret.cost = c;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<long long int> min_dist(n, LONG_LONG_MAX);
  vector<int> parent(n);
  for (int i = 0; i < n; i++) parent[i] = i;
  vector<long long int> incoming_edge(n, LONG_LONG_MAX);
  vector<pair<long long int, long long int> > graph[n];
  vector<node> edges(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    long long int c;
    cin >> a >> b >> c;
    a -= 1;
    b -= 1;
    graph[a].push_back(make_pair(b, c));
    graph[b].push_back(make_pair(a, c));
    edges[i] = create_node(a, b, c);
  }
  int start;
  cin >> start;
  start -= 1;
  min_dist[start] = incoming_edge[start] = 0;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int> >,
                 greater<pair<long long int, long long int> > >
      pq;
  pq.push(make_pair(0, start));
  while (!pq.empty()) {
    pair<long long int, long long int> t = pq.top();
    pq.pop();
    int v = (int)t.second;
    long long int cost = t.first;
    for (int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i].first;
      long long int temp = graph[v][i].second + cost;
      if (temp < min_dist[u]) {
        parent[u] = v;
        min_dist[u] = temp;
        incoming_edge[u] = temp - cost;
        pq.push(make_pair(temp, u));
      } else if (temp == min_dist[u]) {
        if (incoming_edge[u] > (temp - cost)) {
          incoming_edge[u] = temp - cost;
          parent[u] = v;
        }
      }
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) ans += incoming_edge[i];
  cout << ans << endl;
  for (int i = 0; i < m; i++) {
    int a = edges[i].src;
    int b = edges[i].dest;
    if (parent[a] == b || parent[b] == a) cout << i + 1 << " ";
  }
  cout << endl;
  return 0;
}
