#include <bits/stdc++.h>
using namespace std;
struct node {
  long long from;
  long long to;
  long long next;
  long long val;
} edge[350000 << 1];
long long n, m, cnt, src, ans;
long long head[350000], visit[350000], dis[350000], pre[350000];
void init() {
  memset(head, -1, sizeof(head));
  cnt = 0;
}
void addedge(long long from, long long to, long long val) {
  edge[++cnt].from = from;
  edge[cnt].to = to;
  edge[cnt].val = val;
  edge[cnt].next = head[from];
  head[from] = cnt;
}
void SPFA() {
  memset(dis, 0x3f, sizeof(dis));
  memset(visit, 0, sizeof(visit));
  visit[src] = 1;
  dis[src] = 0;
  queue<int> Q;
  Q.push(src);
  while (!Q.empty()) {
    long long u = Q.front();
    Q.pop();
    visit[u] = 0;
    for (long long i = head[u]; i != -1; i = edge[i].next) {
      long long v = edge[i].to;
      if (dis[v] > dis[u] + edge[i].val) {
        dis[v] = dis[u] + edge[i].val;
        pre[v] = i;
        if (!visit[v]) {
          visit[v] = 1;
          Q.push(v);
        }
      } else if (dis[v] == dis[u] + edge[i].val &&
                 edge[i].val < edge[pre[v]].val) {
        pre[v] = i;
      }
    }
  }
}
int main() {
  init();
  scanf("%I64d%I64d", &n, &m);
  for (long long i = 1; i <= m; i++) {
    long long a, b, c;
    scanf("%I64d%I64d%I64d", &a, &b, &c);
    addedge(a, b, c);
    addedge(b, a, c);
  }
  scanf("%I64d", &src);
  SPFA();
  for (long long i = 1; i <= n; i++) {
    if (pre[i]) ans += (edge[pre[i]].val);
  }
  printf("%I64d\n", ans);
  for (long long i = 1; i <= n; i++) {
    if (pre[i]) printf("%I64d ", (pre[i] + 1) / 2);
  }
  return 0;
}
