#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e5 + 7;
int n, m, u, par[NMAX], prew[NMAX], inedg[NMAX], zares[NMAX];
long long d[NMAX], ans;
vector<pair<pair<int, int>, int> > g[NMAX];
vector<int> a;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    g[a].push_back(make_pair(make_pair(b, c), i));
    g[b].push_back(make_pair(make_pair(a, c), i));
  }
  scanf("%d", &u);
  for (int i = 1; i <= n; i++) d[i] = (i == u) ? 0 : 1e18;
  set<pair<long long, int> > s;
  s.insert(make_pair(0, u));
  ans = 0;
  while (!s.empty()) {
    int nxt = s.begin()->second;
    s.erase(s.begin());
    ans += prew[nxt];
    a.push_back(zares[nxt]);
    for (vector<pair<pair<int, int>, int> >::iterator it = g[nxt].begin();
         it != g[nxt].end(); it++) {
      int w = it->first.second;
      int nxxt = it->first.first;
      if (d[nxxt] > d[nxt] + w || (d[nxxt] == d[nxt] + w && prew[nxxt] > w)) {
        s.erase(make_pair(d[nxxt], nxxt));
        d[nxxt] = d[nxt] + w;
        par[nxxt] = nxt;
        prew[nxxt] = w;
        zares[nxxt] = it->second;
        s.insert(make_pair(d[nxxt], nxxt));
      }
    }
  }
  cout << ans << endl;
  for (int i = 1; i < a.size(); i++) cout << a[i] << " ";
  return 0;
}
