#include <bits/stdc++.h>
using namespace std;
const int MAX = 300 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1LL * INF * INF;
const int MOD = 998244353;
const double PI = acos(-1.);
vector<pair<pair<int, int>, int>> edges;
vector<pair<pair<int, int>, int>> g[MAX];
long long d[MAX];
long long answ;
vector<long long> ans;
int from[MAX];
int n, m;
void path(int v) {
  set<pair<long long, long long>> q;
  for (int i = (1); i < (n + 1); ++i) {
    d[i] = LINF;
    if (i != v) q.insert(make_pair(d[i], i));
  }
  from[v] = -1;
  d[v] = 0;
  q.insert(make_pair(0, v));
  while ((int)q.size()) {
    v = q.begin()->second;
    q.erase(q.begin());
    if (from[v] != -1) {
      answ += edges[from[v] - 1].second;
      ans.push_back(from[v]);
    }
    for (int i = (0); i < ((int)g[v].size()); ++i) {
      int to = g[v][i].first.first;
      long long w = g[v][i].first.second;
      if (d[to] > d[v] + w) {
        q.erase(make_pair(d[to], to));
        d[to] = d[v] + w;
        from[to] = g[v][i].second;
        q.insert(make_pair(d[to], to));
      }
      if (d[to] == d[v] + w) {
        int w1 = edges[from[to] - 1].second;
        if (w1 > w) from[to] = g[v][i].second;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = (0); i < (m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (b < a) swap(a, b);
    edges.push_back(make_pair(make_pair(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));
  }
  int u;
  cin >> u;
  answ = 0;
  path(u);
  cout << answ << endl;
  sort(ans.begin(), ans.end());
  for (int i = (0); i < ((int)ans.size()); ++i)
    cout << ans[i] << " \n"[i + 1 == (int)ans.size()];
  return 0;
}
