#include <bits/stdc++.h>
using namespace std;
pair<long long, int> d[300500];
const int inf = (int)1e9;
long long s = 0;
vector<int> ans;
int n, m, u;
vector<pair<pair<int, int>, int> > g[300500];
priority_queue<pair<pair<long long, int>, pair<int, int> > > q;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(make_pair(make_pair(b, c), i + 1));
    g[b].push_back(make_pair(make_pair(a, c), i + 1));
  }
  cin >> u;
  for (int i = 1; i <= n; ++i) {
    d[i] = make_pair(inf * -1ll * inf, -inf);
  }
  d[u] = make_pair(0, 0);
  q.push(make_pair(make_pair(0, 0), make_pair(u, 0)));
  while (!q.empty()) {
    pair<pair<long long, int>, pair<int, int> > cur = q.top();
    q.pop();
    int v = cur.second.first;
    pair<long long, int> cost = cur.first;
    if (d[v] != cost) continue;
    cost.first *= -1ll;
    cost.second *= -1ll;
    if (v != u) ans.push_back(cur.second.second);
    s += cost.second;
    for (int i = 0; i < g[v].size(); ++i) {
      int to = g[v][i].first.first;
      pair<long long, int> ncost = make_pair(
          -d[v].first + g[v][i].first.second * 1ll, g[v][i].first.second);
      pair<long long, int> oldcost =
          make_pair(-1ll * d[to].first, -1ll * d[to].second);
      if (ncost < oldcost) {
        d[to] = make_pair(-1ll * ncost.first, -ncost.second);
        q.push(make_pair(d[to], make_pair(to, g[v][i].second)));
      }
    }
  }
  cout << s << '\n';
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << ' ';
  }
  return 0;
}
