#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, id, next;
  long long int w;
} edges[610000];
int n, m;
int head[610000], nCount = 1;
void AddEdge(int U, int V, long long int W, int ID) {
  edges[++nCount].u = U;
  edges[nCount].v = V;
  edges[nCount].w = W;
  edges[nCount].id = ID;
  edges[nCount].next = head[U];
  head[U] = nCount;
}
long long int dist[610000];
bool vis[610000];
bool used[610000];
int pre[610000];
struct Info {
  int u;
  long long int w;
  long long int dis;
  Info(int _u, long long int _d, long long int _w) : u(_u), dis(_d), w(_w) {}
};
bool operator<(Info a, Info b) {
  if (a.dis == b.dis) return a.w < b.w;
  return a.dis < b.dis;
}
bool operator>(Info a, Info b) {
  if (a.dis == b.dis) return a.w > b.w;
  return a.dis > b.dis;
}
priority_queue<Info, vector<Info>, greater<Info> > heap;
void heapdij(int S) {
  memset(dist, 0x3f, sizeof(dist));
  dist[S] = 0;
  heap.push(Info(S, 0, 0));
  while (!heap.empty()) {
    Info now = heap.top();
    heap.pop();
    int u = now.u;
    if (vis[u]) continue;
    vis[u] = true;
    for (int p = head[u]; p != -1; p = edges[p].next) {
      int v = edges[p].v;
      if (dist[u] + edges[p].w <= dist[v]) {
        if (pre[v] != -1) used[pre[v]] = false;
        pre[v] = edges[p].id;
        used[edges[p].id] = true;
        dist[v] = dist[u] + edges[p].w;
        heap.push(Info(v, dist[v], edges[p].w));
      }
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long int w;
    scanf("%d%d%I64d", &u, &v, &w);
    AddEdge(u, v, w, i);
    AddEdge(v, u, w, i);
  }
  int S;
  scanf("%d", &S);
  heapdij(S);
  long long int tot = 0;
  for (int i = 1; i <= m; i++)
    if (used[i]) tot += (long long int)edges[i * 2].w;
  printf("%I64d\n", tot);
  for (int i = 1; i <= m; i++)
    if (used[i]) printf("%d ", i);
  printf("\n");
  return 0;
}
