#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000001;
int main() {
  int N, M, a;
  scanf("%d %d", &N, &M);
  long long edges[M][3], dist[N], par[N], chk[N];
  vector<int> paths[N];
  for (int i = 0; i < N; i++) {
    dist[i] = 1e18;
    chk[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    scanf("%lld %lld %lld", &edges[i][0], &edges[i][1], &edges[i][2]);
    paths[--edges[i][0]].push_back(i);
    paths[--edges[i][1]].push_back(i);
  }
  scanf("%d", &a);
  a--;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      pq;
  pq.push({0, a});
  dist[a] = 0;
  chk[a] = 1;
  pair<long long, int> cur;
  long long ans = 0;
  vector<int> fin;
  while (!pq.empty()) {
    cur = pq.top();
    pq.pop();
    if (cur.first != dist[cur.second]) continue;
    if (!chk[cur.second]) {
      ans += edges[par[cur.second]][2];
      fin.push_back(par[cur.second]);
      chk[cur.second] = 1;
    }
    for (int i : paths[cur.second]) {
      a = edges[i][0] ^ edges[i][1] ^ cur.second;
      if (dist[cur.second] + edges[i][2] < dist[a] ||
          (dist[cur.second] + edges[i][2] == dist[a] &&
           edges[i][2] < edges[par[a]][2])) {
        dist[a] = dist[cur.second] + edges[i][2];
        par[a] = i;
        pq.push({dist[a], a});
      }
    }
  }
  printf("%lld\n", ans);
  for (int i : fin) {
    printf("%d ", i + 1);
  }
}
