#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
inline long long int max(long long int a, long long int b, long long int c) {
  return max(max(a, b), c);
}
inline long long int min(long long int a, long long int b, long long int c) {
  return min(min(a, b), c);
}
inline long long int max(long long int a, long long int b) {
  return (a > b) ? a : b;
}
inline long long int min(long long int a, long long int b) {
  return (a < b) ? a : b;
}
inline long long int mul(long long int x, long long int y, long long int mod_) {
  return ((x % mod_) * 1LL * (y % mod_)) % mod_;
}
long long int power(long long int a, long long int n) {
  long long int p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long int powm(long long int a, long long int n, long long int mod_) {
  long long int p = 1;
  while (n) {
    if (n % 2) {
      p = mul(p, a, mod_);
    }
    n >>= 1;
    a = mul(a, a, mod_);
  }
  return p % mod_;
}
long long int powi(long long int a, long long int mod_) {
  return powm(a, mod_ - 2, mod_);
}
vector<vector<pair<long long int, long long int>>> g;
vector<long long int> d, p, dep;
set<pair<long long int, long long int>> edges;
map<pair<long long int, long long int>, pair<long long int, long long int>> pos;
void dij(long long int x) {
  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>>>
      q;
  q.push({0, x});
  d[x] = 0;
  while (!q.empty()) {
    pair<long long int, long long int> pp = q.top();
    q.pop();
    for (auto pp1 : g[pp.second]) {
      if ((pp.first + pp1.second < d[pp1.first]) or
          ((pp.first + pp1.second == d[pp1.first]) and
           (pos[{pp1.first, p[pp1.first]}].second >
            pos[{pp.second, pp1.first}].second))) {
        d[pp1.first] = pp.first + pp1.second;
        if (edges.count({pp1.first, p[pp1.first]})) {
          edges.erase({pp1.first, p[pp1.first]});
          edges.erase({p[pp1.first], pp1.first});
        }
        p[pp1.first] = pp.second;
        q.push({d[pp1.first], pp1.first});
        edges.insert({pp1.first, p[pp1.first]});
        edges.insert({p[pp1.first], pp1.first});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int mn, mx;
  long long int n, m, t, k, i, j, sum = 0, flag = 0, cnt = 0;
  long long int x = 0, y = 0, z, l, r, q;
  int TC = 1;
  while (TC--) {
    cin >> n >> m;
    g.resize(n);
    d.assign(n, 2000000000000000000);
    p.assign(n, -1);
    dep.assign(n, 0);
    for (i = 0; i < m; ++i) {
      cin >> x >> y >> z;
      --x;
      --y;
      g[x].push_back({y, z});
      g[y].push_back({x, z});
      pos[{x, y}] = {i + 1, z};
      pos[{y, x}] = {i + 1, z};
    }
    long long int u;
    cin >> u;
    --u;
    dij(u);
    for (auto pp : edges) {
      sum += pos[pp].second;
    }
    sum /= 2;
    cout << sum << '\n';
    set<pair<long long int, long long int>> done;
    for (auto pp1 : edges) {
      if (done.count(pp1)) continue;
      cout << pos[pp1].first << ' ';
      done.insert({pp1.first, pp1.second});
      done.insert({pp1.second, pp1.first});
    }
  };
  return 0;
}
