#include <bits/stdc++.h>
using namespace std;
int n, m, s;
struct edge {
  int from;
  int to;
  int w;
};
edge e[600020];
vector<int> adj[300010];
long long sum, d[300010];
int tag[600010], pre[300010], vis[300010];
queue<int> Q;
void init() {
  int i;
  for (i = 0; i <= n; i++) adj[i].clear();
}
void spfa() {
  while (!Q.empty()) Q.pop();
  memset(tag, 0, sizeof(tag));
  for (int i = 1; i <= n; i++) {
    d[i] = 0x7fffffffffffffff;
    pre[i] = -1;
  }
  d[s] = 0;
  memset(vis, 0, sizeof(vis));
  Q.push(s);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    vis[x] = 0;
    for (int i = 0; i < adj[x].size(); i++) {
      int t = adj[x][i];
      int v = e[t].to;
      if (d[v] > d[x] + e[t].w && d[x] < 0x7fffffffffffffff) {
        pre[v] = t;
        d[v] = d[x] + e[t].w;
        if (!vis[v]) {
          vis[v] = 1;
          Q.push(v);
        }
      } else if (d[v] == d[x] + e[t].w && d[x] < 0x7fffffffffffffff &&
                 e[pre[v]].w > e[t].w)
        pre[v] = t;
    }
  }
}
int main() {
  int i, j, a, b, c;
  while (scanf("%d%d", &n, &m) == 2) {
    init();
    for (i = 1; i <= m; i++) {
      scanf("%d %d %d", &a, &b, &c);
      e[i] = {a, b, c};
      e[i + m] = {b, a, c};
      adj[a].push_back(i);
      adj[b].push_back(i + m);
    }
    scanf("%d", &s);
    spfa();
    sum = 0;
    for (i = 1; i <= n; i++) {
      sum += e[pre[i]].w;
      tag[pre[i]] = 1;
    }
    int count = 0;
    printf("%I64d\n", sum);
    for (i = 1; i <= 2 * m; i++) {
      if (tag[i]) {
        if (count)
          printf(" %d", i > m ? i - m : i);
        else
          printf("%d", i > m ? i - m : i);
        count++;
      }
    }
    printf("\n");
  }
  return 0;
}
