#include <bits/stdc++.h>
using namespace std;
long long dp[300005];
vector<int> adj[300005], pos[300005];
vector<long long> adj_w[300005];
int main() {
  int n, m, u;
  long long results = 0;
  vector<int> ans;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    long long w;
    scanf("%d %d %I64d", &u, &v, &w);
    adj[u].push_back(v);
    pos[u].push_back(i + 1);
    adj[v].push_back(u);
    pos[v].push_back(i + 1);
    adj_w[u].push_back(w);
    adj_w[v].push_back(w);
  }
  scanf("%d", &u);
  for (int i = 1; i <= n; i++) dp[i] = -1;
  queue<int> q;
  q.push(u);
  dp[u] = 0;
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    for (int i = 0; i < adj[top].size(); i++) {
      long long dist = dp[top] + adj_w[top][i];
      if (dp[adj[top][i]] == -1 || dp[adj[top][i]] > dist) {
        dp[adj[top][i]] = dist;
        q.push(adj[top][i]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i != u) {
      int temp = -1;
      for (int j = 0; j < adj[i].size(); j++) {
        if (dp[i] == dp[adj[i][j]] + adj_w[i][j]) {
          if (temp == -1 || adj_w[i][j] < adj_w[i][temp]) temp = j;
        }
      }
      results += adj_w[i][temp];
      ans.push_back(pos[i][temp]);
    }
  }
  printf("%I64d\n", results);
  for (int i = 0; i < ans.size(); i++) {
    printf("%d", ans[i]);
    if (i != ans.size() - 1)
      printf(" ");
    else
      printf("\n");
  }
  return 0;
}
