#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > adj[300001];
long long weight[300001], indice[300001], dist[300001];
struct comp {
  bool operator()(pair<long long, long long> n1,
                  pair<long long, long long> n2) {
    return n1.first > n2.first;
  }
};
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               comp>
    qu;
void dijkstra(int src) {
  long long i, h, node;
  dist[src] = 0;
  qu.push(make_pair(0, src));
  while (!qu.empty()) {
    node = qu.top().second;
    qu.pop();
    h = adj[node].size();
    for (i = 0; i < h; i++) {
      long long next, weig, id;
      next = adj[node][i].first;
      id = adj[node][i].second;
      weig = weight[id];
      if (dist[next] > (dist[node] + weig)) {
        dist[next] = (dist[node] + weig);
        qu.push(make_pair(dist[next], next));
        indice[next] = id;
      } else if (dist[next] == (dist[node] + weig)) {
        if (weig < weight[indice[next]]) {
          indice[next] = id;
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long N, M, X, Y, W, j, i, uup;
  long long sum = 0;
  cin >> N >> M;
  for (i = 1; i <= M; i++) {
    cin >> X >> Y >> W;
    adj[X].push_back(make_pair(Y, i));
    adj[Y].push_back(make_pair(X, i));
    weight[i] = W;
  }
  for (i = 1; i <= N; i++) {
    dist[i] = 9223372036854775807;
  }
  cin >> uup;
  dijkstra(uup);
  for (i = 1; i <= N; i++) {
    sum += weight[indice[i]];
  }
  cout << sum << "\n";
  for (i = 1; i <= N; i++) {
    if (i != uup) {
      cout << indice[i] << " ";
    }
  }
  return 0;
}
