#include <bits/stdc++.h>
using namespace std;
const int MX = 3 * 100000 + 5;
const long long INF = 1LL << 50;
vector<pair<int, pair<int, int> > > g[MX];
long long E[MX];
long long D[MX];
long long e[MX];
void solve(int u) {
  set<pair<int, int> > q;
  D[u] = 0;
  q.insert(pair<int, int>(0, u));
  while (!q.empty()) {
    pair<int, int> top = *q.begin();
    q.erase(q.begin());
    int v = top.second, d = top.first;
    if (d <= D[v]) {
      for (typeof((g[v]).begin()) it = (g[v]).begin(); it != (g[v]).end();
           it++) {
        int v2 = it->first, cost = it->second.first;
        if (D[v2] >= D[v] + cost) {
          if (D[v2] != INF) {
          }
          D[v2] = D[v] + cost;
          q.insert(pair<int, int>(D[v2], v2));
          E[v2] = it->second.second;
        }
      }
    }
  }
}
int main(int argc, char *argv[]) {
  ios ::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, u, v, w;
  cin >> n >> m;
  for (int i = (0), _b = (m); i < (_b); ++i) {
    cin >> u >> v >> w;
    g[u].push_back(pair<int, pair<int, int> >(v, pair<int, int>(w, i + 1)));
    g[v].push_back(pair<int, pair<int, int> >(u, pair<int, int>(w, i + 1)));
    e[i + 1] = w;
  }
  cin >> u;
  for (int i = (0), _b = (MX); i < (_b); ++i) D[i] = INF;
  solve(u);
  long long ans = 0;
  vector<int> vv;
  for (int i = (1), _b = (MX); i < (_b); ++i) {
    if (E[i]) {
      vv.push_back(E[i]);
      ans += e[E[i]];
    }
  }
  sort((vv).begin(), (vv).end());
  cout << ans << '\n';
  for (int i = (0), _b = (vv.size()); i < (_b); ++i) cout << vv[i] << " ";
  cout << '\n';
  return 0;
}
