#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 5;
const long long INF = numeric_limits<long long>::max();
struct dijkstra {
  long long dis[N], prev[N], prev_w[N];
  vector<int> res;
  void init() {
    for (int i = 0; i < N; ++i) {
      dis[i] = INF / 2;
    }
  }
  long long calc(vector<vector<tuple<int, int, int>>>& g, int s) {
    long long re = 0;
    dis[s] = 0;
    prev[s] = -1;
    int size = g.size();
    set<pair<long long, int>> se;
    for (int i = 0; i < size; ++i) {
      se.insert({dis[i], i});
    }
    while (!se.empty()) {
      set<pair<long long, int>>::iterator it = se.begin();
      int v = it->second;
      se.erase(it);
      if (prev[v] > 0) {
        res.push_back(prev[v]);
        re += prev_w[v];
        if (res.size() == g.size() - 1) break;
      }
      for (int i = 0; i < (int)g[v].size(); ++i) {
        int u, di, id;
        tie(u, di, id) = g[v][i];
        if (dis[v] + (long long)di == dis[u] && di < prev_w[u]) {
          prev[u] = id;
          prev_w[u] = di;
        }
        if (dis[v] + di < dis[u]) {
          se.erase({dis[u], u});
          se.insert({dis[v] + di, u});
          dis[u] = dis[v] + di;
          prev[u] = id;
          prev_w[u] = di;
        }
      }
    }
    return re;
  }
} dij;
int main() {
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<tuple<int, int, int>>> g(n);
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    --u;
    --v;
    g[u].push_back(make_tuple(v, w, i + 1));
    g[v].push_back(make_tuple(u, w, i + 1));
  }
  int u;
  cin >> u;
  --u;
  dij.init();
  cout << dij.calc(g, u) << endl;
  assert(dij.res.size() == n - 1);
  for (int i = 0; i < n - 1; ++i) {
    cout << dij.res[i] << " ";
  }
  cout << endl;
  return 0;
}
