#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 5, inf = 1e18;
vector<pair<pair<long long, long long>, long long>> g[maxn];
long long dist[maxn], pr[maxn];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    long long u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    g[u].push_back({{v, w}, i});
    g[v].push_back({{u, w}, i});
  }
  set<pair<long long, long long>> second;
  for (long long i = 0; i < n; ++i) {
    dist[i] = inf;
  }
  long long kek;
  cin >> kek;
  kek--;
  dist[kek] = 0;
  for (long long i = 0; i < n; ++i) {
    second.insert({dist[i], i});
  }
  while (!second.empty()) {
    long long v = second.begin()->second;
    second.erase(second.begin());
    for (auto [e, i] : g[v]) {
      auto [u, w] = e;
      if (dist[u] > dist[v] + w) {
        second.erase({dist[u], u});
        dist[u] = dist[v] + w;
        second.insert({dist[u], u});
      }
    }
  }
  long long ans = 0;
  vector<long long> a;
  for (long long i = 0; i < n; ++i) {
    if (i == kek) {
      continue;
    }
    pr[i] = -1;
    long long second = -1;
    for (auto [e, j] : g[i]) {
      if (dist[i] == dist[e.first] + e.second &&
          (pr[i] == -1 || e.second < second)) {
        second = e.second;
        pr[i] = j;
      }
    }
    ans += second;
    a.push_back(pr[i] + 1);
  }
  cout << ans << '\n';
  for (auto e : a) {
    cout << e << ' ';
  }
  return 0;
}
