#include <bits/stdc++.h>
using namespace std;
struct are {
  int x, y;
  long long int p;
  int id;
  are() { x = y = p = 0; }
  are(int a, int b, long long int c) {
    x = a;
    y = b;
    p = c;
    id = a + 1;
  }
  bool operator<(are a) const {
    if (p != a.p) return p > a.p;
    if (x != a.x) return x < a.x;
    if (y != a.y) return y < a.y;
    return id < a.id;
  }
} v[300005];
vector<are> G[300005];
int grupo[300005];
long long int dist[300005];
int marca[300005];
int esta[300005];
void iniciar(int n) {
  memset(marca, 0, sizeof marca);
  memset(esta, 0, sizeof esta);
  for (int i = 0; i <= n; i++) {
    grupo[i] = i;
    dist[i] = 20000000000000000LL;
    G[i].clear();
  }
}
void D(int s) {
  priority_queue<are> fila;
  dist[s] = 0;
  fila.push(are(0, s, 0));
  are t;
  while (fila.size() > 0) {
    t = fila.top();
    fila.pop();
    int v = t.y;
    long long int p = t.p;
    if (dist[v] < p) continue;
    for (int i = 0; i < G[v].size(); i++) {
      int r = G[v][i].y;
      if (dist[r] > p + G[v][i].p) {
        dist[r] = p + G[v][i].p;
        fila.push(are(0, r, dist[r]));
      }
    }
  }
}
int main() {
  int n, m;
  int i, j;
  int a, b, c;
  long long int ans, menor;
  scanf("%d %d", &n, &m);
  iniciar(n);
  for (i = 0; i < m; i++) {
    cin >> v[i].x >> v[i].y >> v[i].p;
    if (v[i].x > v[i].y) swap(v[i].x, v[i].y);
    G[v[i].x].push_back(are(v[i].x, v[i].y, v[i].p));
    G[v[i].y].push_back(are(v[i].y, v[i].x, v[i].p));
    v[i].id = (i + 1);
  }
  scanf("%d", &a);
  D(a);
  ans = 0;
  sort(v, v + m);
  for (i = m - 1; i >= 0; i--) {
    if (!marca[v[i].x] && dist[v[i].x] - v[i].p == dist[v[i].y]) {
      ans += v[i].p;
      marca[v[i].x] = true;
      esta[v[i].id] = true;
    }
    if (!marca[v[i].y] && dist[v[i].y] - v[i].p == dist[v[i].x]) {
      ans += v[i].p;
      marca[v[i].y] = true;
      esta[v[i].id] = true;
    }
  }
  cout << ans << endl;
  for (i = 1; i <= m; i++)
    if (esta[i]) printf("%d ", i);
  printf("\n");
}
