#include <bits/stdc++.h>
int cnt = 0;
long long dis[300005];
int vis[300005], pre[300005];
int h[300005], to[600005], ver[600005], w[600005];
inline int read() {
  register int x = 0, f = 1;
  register char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline void add(int x, int y, int z) {
  to[++cnt] = y;
  ver[cnt] = h[x];
  w[cnt] = z;
  h[x] = cnt;
}
inline void dijistra(int u) {
  std::priority_queue<std::pair<long long, int> > Q;
  memset(dis, 0x3f, sizeof(dis));
  Q.push(std::make_pair(0, u));
  dis[u] = 0;
  while (Q.size()) {
    int x = Q.top().second;
    Q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (register int i = h[x]; i; i = ver[i]) {
      int y = to[i];
      if (dis[y] >= dis[x] + w[i]) {
        dis[y] = dis[x] + w[i];
        pre[y] = i;
        Q.push(std::make_pair(-dis[y], y));
      }
    }
  }
}
int main() {
  int n = read(), m = read();
  for (register int i = 1; i <= m; ++i) {
    int x = read(), y = read(), z = read();
    add(x, y, z);
    add(y, x, z);
  }
  int u = read();
  dijistra(u);
  long long ans = 0;
  for (register int i = 1; i <= n; ++i) ans += w[pre[i]];
  printf("%lld\n", ans);
  for (register int i = 1; i <= n; ++i) pre[i] = (pre[i] + 1) >> 1;
  std::sort(pre + 1, pre + 1 + n);
  for (register int i = 2; i <= n; ++i) printf("%d ", pre[i]);
  return 0;
}
