#include <bits/stdc++.h>
using namespace std;
struct edge {
  int f, s, idx;
};
long long dist[300001];
vector<edge> vec[300001];
int minedge[300001], antman[300001];
bitset<300001> vis;
void dijkstra(int a) {
  dist[a] = 0;
  set<pair<long long, int>> se;
  se.insert({0, a});
  while (!se.empty()) {
    int r = se.begin()->second;
    se.erase(se.begin());
    if (vis[r]) continue;
    vis[r] = true;
    for (int i = 0; i < vec[r].size(); i++) {
      int e = vec[r][i].f, q = vec[r][i].s;
      if (dist[e] > dist[r] + q || (dist[e] == dist[r] + q && minedge[e] > q)) {
        minedge[e] = q;
        dist[e] = dist[r] + q;
        antman[e] = vec[r][i].idx;
        se.insert({dist[e], e});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int x, y, a, b, c;
  cin >> x >> y;
  for (int i = 1; i <= x; i++) {
    dist[i] = (long long)2e18;
    minedge[i] = (int)2e9;
  }
  for (int i = 0; i < y; i++) {
    cin >> a >> b >> c;
    vec[a].push_back({b, c, i});
    vec[b].push_back({a, c, i});
  }
  cin >> a;
  dijkstra(a);
  long long ans = 0;
  for (int i = 1; i <= x; i++) {
    if (i != a) ans += minedge[i];
  }
  cout << ans << endl;
  for (int i = 1; i <= x; i++) {
    if (i != a) cout << (antman[i] + 1) << ' ';
  }
}
