#include <bits/stdc++.h>
using namespace std;
vector<long long> e[300010], w[300010], z[300010];
priority_queue<pair<long long, long long> > pq;
long long vis[300010], a[300010], ans[300010], s[300010], g[300010];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long n, m, u, v, wi, t;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> wi;
    e[u].push_back(v);
    e[v].push_back(u);
    w[u].push_back(wi);
    w[v].push_back(wi);
    z[u].push_back(i);
    z[v].push_back(i);
    g[i] = wi;
  }
  cin >> t;
  memset(a, 0x3f3f3f3f, sizeof(a));
  memset(ans, -1, sizeof(ans));
  a[t] = 0;
  pq.push(make_pair(0, t));
  while (!pq.empty()) {
    int k = pq.top().second;
    pq.pop();
    if (vis[k]) continue;
    vis[k] = 1;
    for (int i = 0; i < e[k].size(); i++) {
      int x = e[k][i];
      if (vis[x]) continue;
      if (a[x] >= a[k] + w[k][i]) {
        a[x] = a[k] + w[k][i];
        if (ans[x] != -1) s[ans[x]] = 0;
        ans[x] = z[k][i];
        s[ans[x]] = 1;
        pq.push(make_pair(-a[x], x));
      }
    }
  }
  long long tot = 0;
  for (int i = 0; i < m; i++) {
    if (s[i]) tot += g[i];
  }
  cout << tot << endl;
  for (int i = 0; i < m; i++)
    if (s[i]) cout << i + 1 << " ";
  return 0;
}
