#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
const long long INF = 1e16;
struct E {
  int v, next, w, id;
} edge[maxn * 2];
int N, M;
int st;
long long dis[maxn];
bool vis[maxn];
int W[maxn];
int head[maxn], tot;
int pre[maxn], cnt[maxn];
void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
  memset(pre, 0, sizeof(pre));
  memset(cnt, 0, sizeof(cnt));
}
void add_edge(int u, int v, int w, int id) {
  edge[tot].v = v;
  edge[tot].next = head[u];
  edge[tot].w = w;
  edge[tot].id = id;
  head[u] = tot++;
}
void SPFA() {
  for (int i = 0; i <= N; i++) dis[i] = INF, vis[i] = 0;
  queue<int> q;
  q.push(st);
  dis[st] = 0;
  vis[st] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      int w = edge[i].w;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        pre[v] = edge[i].id;
        if (!vis[v]) {
          q.push(v);
          vis[v] = 1;
        }
      } else if (dis[v] == dis[u] + w) {
        if (w < W[pre[v]]) {
          pre[v] = edge[i].id;
          if (!vis[v]) {
            q.push(v);
            vis[v] = 1;
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &N, &M);
  init();
  for (int i = 1; i <= M; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add_edge(u, v, w, i);
    add_edge(v, u, w, i);
    W[i] = w;
  }
  scanf("%d", &st);
  SPFA();
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= N; i++) vis[pre[i]] = 1;
  long long sum = 0;
  for (int i = 1; i <= N; i++)
    if (pre[i] > 0) sum += W[pre[i]];
  cout << sum << endl;
  for (int i = 1; i <= N; i++)
    if (pre[i]) printf("%d ", pre[i]);
  printf("\n");
  return 0;
}
