#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > ed[300005];
int n, m;
int pa[300005];
long long int vis[300005];
void solve() {
  cin >> n >> m;
  long long int u;
  long long ww[m], pre[n + 1];
  pair<long long, long long> edg[m];
  for (int i = 0; i < m; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    ed[u].push_back(pair<long long, long long>(v, w));
    ed[v].push_back(pair<long long, long long>(u, w));
    edg[i] = pair<long long, long long>(u, v);
    ww[i] = w;
  }
  cin >> u;
  priority_queue<pair<long long, long long> > pq;
  long long d[n + 1];
  for (int i = 0; i < n; i++) pre[i + 1] = d[i + 1] = 1e18 + 1;
  d[u] = 0;
  pre[u] = 0;
  pq.push(pair<long long, long long>(0, u));
  while (!pq.empty()) {
    pair<long long, long long> p = pq.top();
    pq.pop();
    if (vis[p.second]) continue;
    vis[p.second] = 1;
    for (pair<long long, long long> j : ed[p.second]) {
      if (d[j.first] > j.second - p.first) {
        d[j.first] = j.second - p.first;
        pa[j.first] = p.second;
        pre[j.first] = j.second;
        pq.push(pair<long long, long long>(-d[j.first], j.first));
      } else if (d[j.first] == j.second - p.first && j.second < pre[j.first]) {
        pa[j.first] = p.second;
        pre[j.first] = j.second;
      }
    }
  }
  vector<int> res;
  long long wt = 0;
  for (int i = 0; i < m; i++) {
    long long u, v;
    u = edg[i].first;
    v = edg[i].second;
    if (u == pa[v] || pa[u] == v) {
      wt += ww[i];
      res.push_back(i + 1);
    }
  }
  cout << wt << "\n";
  for (int i : res) cout << i << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
