#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
long long dis[MAXN], c1, ans;
bool vis[MAXN], inqq[MAXN], f[MAXN];
int s, t, q[MAXN], head, tail, tot, T, S, D, a1, b1, g[MAXN], aa[MAXN],
    pre[MAXN], ll, m, n;
struct edges {
  int to;
  long long v;
  int ki;
  int next;
} e[800005];
void add_edge(int from, int to, long long v, int ki) {
  e[++tot].to = to;
  e[tot].v = v;
  e[tot].next = g[from];
  e[tot].ki = ki;
  g[from] = tot;
  return;
}
void cleans() {
  for (int i = 0; i <= n; ++i) {
    g[i] = 0;
    vis[i] = false;
    dis[i] = 1152921504606846976LL;
  }
  tot = 0;
  head = 0;
  tail = 0;
}
void spfa() {
  q[++tail] = s;
  dis[s] = 0;
  vis[s] = true;
  while (head != tail) {
    head = head % 300001 + 1;
    for (int i = g[q[head]]; i; i = e[i].next) {
      if (dis[e[i].to] > dis[q[head]] + e[i].v) {
        ans -= e[pre[e[i].to]].v;
        ans += e[i].v;
        pre[e[i].to] = i;
        dis[e[i].to] = dis[q[head]] + e[i].v;
        if (!vis[e[i].to]) {
          tail = tail % 300001 + 1;
          q[tail] = e[i].to;
          vis[q[tail]] = true;
        }
      } else if (dis[e[i].to] == dis[q[head]] + e[i].v) {
        if (e[pre[e[i].to]].v > e[i].v) {
          ans -= e[pre[e[i].to]].v;
          ans += e[i].v;
          pre[e[i].to] = i;
        }
      }
    }
    vis[q[head]] = false;
  }
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  cleans();
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %I64d", &a1, &b1, &c1);
    add_edge(a1, b1, c1, i);
    add_edge(b1, a1, c1, i);
  }
  scanf("%d", &s);
  spfa();
  for (int i = 1; i <= n; ++i) {
    if (pre[i]) aa[++ll] = e[pre[i]].ki;
  }
  printf("%I64d\n", ans);
  sort(aa + 1, aa + 1 + ll);
  if (ll) {
    printf("%d", aa[1]);
    for (int i = 2; i <= ll; ++i) {
      printf(" %d", aa[i]);
    }
    printf("\n");
  }
  return 0;
}
