#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int n, m, st, vis[maxn], fre[maxn];
long long dis[maxn], ans;
int head[maxn], cnt = -1;
struct edge {
  int to, next, w;
} e[maxn << 1];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
void adde(int u, int v, int w) {
  e[++cnt].to = v;
  e[cnt].w = w;
  e[cnt].next = head[u];
  head[u] = cnt;
}
int read() {
  int res = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (!isdigit(ch));
  do {
    res = res * 10 + ch - '0';
    ch = getchar();
  } while (isdigit(ch));
  return res * f;
}
void Dijkstra() {
  dis[st] = 0;
  fre[st] = -1;
  q.push(make_pair(dis[st], st));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = head[u]; i != -1; i = e[i].next) {
      int v = e[i].to;
      if (dis[v] == dis[u] + e[i].w) {
        if (e[fre[v]].w > e[i].w) {
          fre[v] = i;
          if (!vis[v]) q.push(make_pair(dis[v], v));
        }
      }
      if (dis[v] > dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        fre[v] = i;
        if (!vis[v]) q.push(make_pair(dis[v], v));
      }
    }
  }
}
int main() {
  n = read();
  m = read();
  memset(head, -1, sizeof(head));
  for (int i = (0); i <= (n); ++i) dis[i] = 1e18;
  for (int i = (1); i <= (m); ++i) {
    int u = read(), v = read(), w = read();
    adde(u, v, w);
    adde(v, u, w);
  }
  st = read();
  Dijkstra();
  for (int i = (1); i <= (n); ++i)
    if (fre[i] != -1) ans += e[fre[i]].w;
  printf("%lld\n", ans);
  for (int i = (1); i <= (n); ++i)
    if (fre[i] != -1) printf("%d ", fre[i] / 2 + 1);
  return 0;
}
