#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 5;
const long long oo = 1e18;
array<int, 3> E[N];
long long f[N], g[N], to[N];
vector<int> ke[N];
void dij(int n) {
  int s;
  cin >> s;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      h;
  for (int i = 1; i <= n; ++i) f[i] = oo;
  h.push({f[s] = 0, s});
  while (!h.empty()) {
    int u = h.top().second;
    long long s = h.top().first;
    h.pop();
    if (s != f[u]) continue;
    for (int j : ke[u]) {
      array<int, 3> e = E[j];
      int v = e[0] + e[1] - u, w = e[2];
      if (s + w < f[v]) {
        h.push({f[v] = s + w, v});
        g[to[v]] = 0;
        g[to[v] = j] = 1;
      } else if (s + w == f[v] && w < E[to[v]][2])
        g[to[v]] = false, g[to[v] = j] = true;
    }
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j <= 2; ++j) cin >> E[i][j];
    ke[E[i][0]].push_back(i);
    ke[E[i][1]].push_back(i);
  }
  dij(n);
  long long s = 0;
  for (int i = 1; i <= m; ++i) s += g[i] * E[i][2];
  cout << s << "\n";
  for (int i = 1; i <= m; ++i)
    if (g[i]) cout << i << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
