#include <bits/stdc++.h>
using namespace std;
const long long MX = 300005;
long long n, E;
vector<tuple<long long, long long, long long> > adj[MX];
long long d[MX];
long long ls[MX];
long long vis[MX];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> E;
  for (long long i = 0; i < E; ++i) {
    long long x, y, w;
    cin >> x >> y >> w;
    adj[x].push_back(make_tuple(w, y, i + 1));
    adj[y].push_back(make_tuple(w, x, i + 1));
  }
  for (long long i = 1; i <= n; ++i) sort(adj[i].begin(), adj[i].end());
  long long s;
  cin >> s;
  memset(d, 0x3f, sizeof d);
  memset(ls, 0x3f, sizeof ls);
  d[s] = 0;
  priority_queue<tuple<long long, long long, long long, long long>,
                 vector<tuple<long long, long long, long long, long long> >,
                 greater<tuple<long long, long long, long long, long long> > >
      q;
  q.push(make_tuple(0, 0, 0, s));
  vector<long long> res;
  long long ans = 0;
  while (!q.empty()) {
    long long x, w, l, r;
    tie(w, l, r, x) = q.top();
    q.pop();
    if (vis[x] || d[x] != w) continue;
    vis[x] = 1;
    res.push_back(r);
    ans += l;
    for (long long i = 0; i < adj[x].size(); ++i) {
      long long nx, nw, id;
      tie(nw, nx, id) = adj[x][i];
      if (d[nx] > w + nw) {
        d[nx] = w + nw;
        q.push(make_tuple(nw + w, nw, id, nx));
        ls[nx] = nw;
      } else if (d[nx] == w + nw && nw < ls[nx]) {
        q.push(make_tuple(nw + w, nw, id, nx));
        ls[nx] = nw;
      }
    }
  }
  cout << ans << "\n";
  for (long long i = 1; i < res.size(); ++i) {
    cout << res[i] << " ";
  }
  return 0;
}
