#include <bits/stdc++.h>
using namespace std;
struct Node {
  int v, w, i;
  Node() {}
  Node(int v, int w, int i) : v(v), w(w), i(i) {}
} node[300001];
list<Node> adj[300001];
int n, m, x, y, z, k;
priority_queue<pair<long long, int> > q1;
int dead[300001];
long long weight[300001];
int ans[300001];
void run(int k) {
  weight[k] = 0;
  q1.push(pair<long long, int>(-0, k));
  while (!q1.empty()) {
    pair<long long, int> top = q1.top();
    q1.pop();
    if (dead[top.second]) continue;
    dead[top.second] = 1;
    for (list<Node>::iterator it = adj[top.second].begin();
         it != adj[top.second].end(); ++it)
      if (weight[top.second] + it->w == weight[it->v]) {
        if (node[ans[it->v]].w > it->w) ans[it->v] = it->i;
      } else if (weight[top.second] + it->w < weight[it->v]) {
        weight[it->v] = weight[top.second] + it->w;
        ans[it->v] = it->i;
        q1.push(pair<long long, int>(-weight[it->v], it->v));
      }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  memset(weight, 0x3f, sizeof(weight));
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d ", &x, &y, &z);
    node[i] = Node(y, z, i);
    adj[x].push_back(node[i]);
    adj[y].push_back(Node(x, z, i));
  }
  scanf("%d", &k), run(k);
  long long tot = 0;
  for (int i = 1; i <= n; i++)
    if (i != k) tot += node[ans[i]].w;
  printf("%I64d\n", tot);
  for (int i = 1; i <= n; i++)
    if (i != k) printf("%d ", ans[i]);
  return 0;
}
