#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const long long inf = 1e18;
int n, m, s;
struct edge {
  int v;
  int w;
  int id;
  edge(int v = 0, int w = 0, int id = 0) : v(v), w(w), id(id) {}
};
vector<edge> G[N];
long long d[N];
vector<pair<int, int> > T[N];
long long ans;
vector<int> vec;
void dijkstra() {
  for (int i = 1; i <= n; ++i) d[i] = inf;
  d[s] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      pq;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    pair<long long, int> t = pq.top();
    pq.pop();
    long long du = t.first;
    int u = t.second;
    if (du != d[u]) continue;
    for (int i = 0; i < G[u].size(); ++i) {
      int v = G[u][i].v, w = G[u][i].w;
      if (d[v] > du + w) d[v] = du + w, pq.push(pair<long long, int>(d[v], v));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back(edge(v, w, i));
    G[v].push_back(edge(u, w, i));
  }
  cin >> s;
  dijkstra();
  for (int u = 1; u <= n; ++u) {
    for (int i = 0; i < G[u].size(); ++i) {
      int v = G[u][i].v, w = G[u][i].w, id = G[u][i].id;
      if (d[v] == d[u] + w) T[v].push_back(make_pair(w, id));
    }
  }
  for (int i = 1; i <= n; ++i)
    if (T[i].size()) {
      sort(T[i].begin(), T[i].end());
      ans += T[i][0].first;
      vec.push_back(T[i][0].second);
    }
  printf("%lld\n", ans);
  for (int id : vec) printf("%d ", id);
  printf("\n");
}
