#include <bits/stdc++.h>
using namespace std;
const int N = 600010;
const long long inf = 1e17;
int n, m, st, head[N], e, ans[300010];
long long dis[300010];
struct edge {
  int u, w, next, p;
} edge[N];
void init() {
  memset(head, -1, sizeof head);
  for (int i = 1; i <= n; ++i) dis[i] = inf;
  e = 1;
}
void add(int u, int v, int w, int i) {
  edge[e].u = v, edge[e].w = w, edge[e].p = i;
  edge[e].next = head[u];
  head[u] = e++;
}
void dij() {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  q.push(pair<long long, int>(0, st));
  long long l;
  int v, u;
  dis[st] = 0;
  while (!q.empty()) {
    u = q.top().second;
    q.pop();
    for (int i = head[u]; i != -1; i = edge[i].next) {
      l = dis[u] + edge[i].w;
      v = edge[i].u;
      if (l < dis[v]) {
        dis[v] = l;
        q.push(pair<long long, int>(l, v));
      }
    }
  }
}
void solve() {
  dij();
  int num = 1, now, id;
  long long sum = 0, tp;
  for (int i = 1; i <= n; ++i) {
    if (i == st) continue;
    tp = inf;
    for (int j = head[i]; j != -1; j = edge[j].next) {
      now = edge[j].u;
      if (dis[i] == dis[now] + edge[j].w && tp > edge[j].w) {
        tp = edge[j].w;
        id = edge[j].p;
      }
    }
    sum += tp;
    ans[num++] = id;
  }
  printf("%I64d\n", sum);
  for (--num; num; --num) printf(num != 1 ? "%d " : "%d\n", ans[num]);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    init();
    int u, v, w;
    for (int i = 1; i <= m; ++i) {
      scanf("%d%d%d", &u, &v, &w);
      add(u, v, w, i);
      add(v, u, w, i);
    }
    scanf("%d", &st);
    solve();
  }
  return 0;
}
