#include <bits/stdc++.h>
using namespace std;
typedef struct edge {
  int index, st, en;
  long long length, dist;
  bool operator<(edge a) const {
    return dist > a.dist || (dist == a.dist && length > a.length);
  }
};
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int path[n + 5];
  bool check[n + 5];
  memset(check, false, sizeof(check));
  long long ans = 0;
  vector<edge> V[n + 1];
  for (int i = 0; i < k; i++) {
    int a, b;
    long long c;
    scanf("%d %d %I64d", &a, &b, &c);
    edge temp;
    temp.length = c;
    temp.st = a;
    temp.en = b;
    temp.index = i + 1;
    temp.dist = 1e10;
    V[a].push_back(temp);
    temp.st = b;
    temp.en = a;
    V[b].push_back(temp);
  }
  priority_queue<edge> Q;
  int start;
  scanf("%d", &start);
  int sz = V[start].size();
  for (int i = 0; i < sz; i++) {
    edge temp = V[start][i];
    temp.dist = temp.length;
    Q.push(temp);
  }
  check[start] = true;
  int c = 0;
  while (!Q.empty()) {
    if (!check[Q.top().en]) {
      ans += Q.top().length;
      path[c++] = Q.top().index;
      long long a = Q.top().dist;
      check[Q.top().en] = true;
      int nn = Q.top().en;
      Q.pop();
      int t = V[nn].size();
      for (int i = 0; i < t; i++) {
        edge temp = V[nn][i];
        temp.dist = temp.length + a;
        Q.push(temp);
      }
    } else
      Q.pop();
  }
  printf("%I64d\n", ans);
  for (int i = 0; i < c; i++) printf("%d ", path[i]);
}
