#include <bits/stdc++.h>
using namespace std;
long long elen, head[300010 << 1], n, m, ans, x, y, z, d[300010 << 1],
    vis[300010 << 1], pre[300010 << 1];
priority_queue<pair<long long, long long> > q;
struct node {
  long long to, nxt, l;
} edge[300010 << 1];
inline long long read() {
  long long x = 0, tag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') tag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * tag;
}
void add(long long x, long long y, long long z) {
  edge[++elen].to = y;
  edge[elen].nxt = head[x];
  edge[elen].l = z;
  head[x] = elen;
}
signed main() {
  elen = 1;
  edge[1].l = 1000000001;
  n = read();
  m = read();
  for (long long i = 1; i <= m; i++)
    x = read(), y = read(), z = read(), add(x, y, z), add(y, x, z);
  x = read();
  memset(d, 0x3f, sizeof(d));
  q.push(pair<long long, long long>(d[x] = 0, x));
  for (long long i = 1; i <= n; i++) {
    while (vis[q.top().second]) q.pop();
    pair<long long, long long> now = q.top();
    now.first = -now.first;
    q.pop();
    vis[now.second] = 1;
    for (long long j = head[now.second]; j; j = edge[j].nxt) {
      long long to = edge[j].to;
      if (d[to] > now.first + edge[j].l ||
          (d[to] == now.first + edge[j].l && edge[j].l < edge[pre[to]].l)) {
        d[to] = now.first + edge[j].l;
        q.push(pair<long long, long long>(-d[to], to));
        pre[to] = j;
      }
    }
  }
  for (long long i = 1; i <= n; i++)
    if (i != x) ans += edge[pre[i]].l;
  printf("%lld\n", ans);
  for (long long i = 1; i <= n; i++)
    if (i != x) printf("%lld ", pre[i] >> 1);
  return 0;
}
