#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 100000 + 5;
const long long INF = 0x0123456789ABCDEFLL;
vector<pair<pair<long long, long long>, long long> > edges[maxn];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    Q;
vector<long long> dist(maxn, INF), dad(maxn, -1), D(maxn, -1), W(maxn, -1);
int u;
void dijkstra(int s) {
  Q.push(make_pair(0, s));
  dist[s] = 0;
  while (!Q.empty()) {
    pair<int, int> p = Q.top();
    Q.pop();
    long long here = p.second;
    for (vector<pair<pair<long long, long long>, long long> >::iterator it =
             edges[here].begin();
         it != edges[here].end(); it++) {
      if (dist[here] + it->first.second < dist[it->first.first]) {
        dist[it->first.first] = dist[here] + it->first.second;
        dad[it->first.first] = it->second;
        D[it->first.first] = dist[here];
        W[it->first.first] = it->first.second;
        Q.push(make_pair(dist[it->first.first], it->first.first));
      } else if (dist[here] + it->first.second == dist[it->first.first]) {
        if (dist[here] > D[it->first.first]) {
          dad[it->first.first] = it->second;
          D[it->first.first] = dist[here];
          W[it->first.first] = it->first.second;
        }
      }
    }
  }
}
inline void solve(void) {
  long long n, m, x, y, z;
  cin >> n >> m;
  for (int i = (0); i < (m); i++) {
    cin >> x >> y >> z;
    edges[x].push_back(pair<pair<int, int>, int>(pair<int, int>(y, z), i + 1));
    edges[y].push_back(pair<pair<int, int>, int>(pair<int, int>(x, z), i + 1));
  }
  cin >> u;
  dijkstra(u);
  long long x1 = 0;
  for (int i = 1; i <= n; i++) {
    if (i == u) continue;
    x1 += W[i];
  }
  cout << x1 << endl;
  for (int i = 1; i <= n; i++) {
    if (i == u) continue;
    cout << dad[i] << " ";
  }
}
void init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
int main(int argc, const char* argv[]) {
  init();
  solve();
  return 0;
}
