#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, n2, x, y, c, u, v, ans, i, len;
  cin >> n >> n2;
  vector<long long> d(n, 1e18 + 7), pred(n, -1), upc(n, 0);
  vector<pair<long long, long long> > reb;
  vector<vector<pair<long long, long long> > > g(n);
  for (i = 0; i < n2; i++) {
    scanf("%lld", &x);
    scanf("%lld", &y);
    scanf("%lld", &c);
    x--;
    y--;
    g[x].push_back({y, c});
    g[y].push_back({x, c});
    reb.push_back({x, y});
  }
  cin >> v;
  v--;
  d[v] = 0;
  set<pair<long long, long long> > s;
  s.insert({d[v], v});
  u = v;
  for (i = 0; i < n; i++) {
    v = s.begin()->second;
    s.erase(s.begin());
    for (auto j : g[v]) {
      len = d[v] + j.second;
      if (d[j.first] > len) {
        s.erase({d[j.first], j.first});
        d[j.first] = len;
        upc[j.first] = j.second;
        pred[j.first] = v;
        s.insert({d[j.first], j.first});
      } else {
        if (d[j.first] == len) {
          if (upc[j.first] > j.second) {
            pred[j.first] = v;
            upc[j.first] = j.second;
          }
        }
      }
    }
  }
  ans = 0;
  for (i = 0; i < n; i++) {
    ans += upc[i];
  }
  printf("%lld\n", ans);
  for (i = 0; i < n2; i++) {
    if (reb[i].first == pred[reb[i].second] ||
        reb[i].second == pred[reb[i].first])
      printf("%lld ", i + 1);
  }
  return 0;
}
