#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<long long int, long long int>>> adj[n + 5];
  long long int x, y, w, idx, wei;
  vector<long long int> weights(m);
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> w;
    adj[x].emplace_back(i, make_pair(w, y));
    adj[y].emplace_back(i, make_pair(w, x));
    weights[i] = w;
  }
  int st;
  cin >> st;
  vector<bool> vis(n + 5, false);
  vector<long long int> rel(m + 5, false), cur(m + 5, -1),
      dist(n + 5, LLONG_MAX / 2);
  priority_queue<pair<long long int, long long int>> Q;
  Q.emplace(0, st);
  dist[st] = 0;
  while (!Q.empty()) {
    auto X = Q.top();
    tie(w, x) = X;
    Q.pop();
    w = -w;
    for (auto to : adj[x]) {
      idx = to.first;
      y = to.second.second;
      wei = to.second.first;
      if (dist[x] + wei == dist[y] and weights[idx] < weights[cur[y]]) {
        dist[y] = dist[x] + wei;
        Q.emplace(-dist[y], y);
        rel[idx] = true;
        if (cur[y] != -1) {
          rel[cur[y]] = false;
        }
        cur[y] = idx;
      }
      if (dist[x] + wei < dist[y]) {
        dist[y] = dist[x] + wei;
        Q.emplace(-dist[y], y);
        rel[idx] = true;
        if (cur[y] != -1) {
          rel[cur[y]] = false;
        }
        cur[y] = idx;
      }
    }
  }
  long long int ans = 0;
  for (int i = 0; i < rel.size(); i++)
    if (rel[i]) ans += weights[i];
  cout << ans << '\n';
  for (int i = 0; i < m + 5; i++)
    if (rel[i]) cout << i + 1 << ' ';
  cout << '\n';
}
