#include <bits/stdc++.h>
using namespace std;
struct edge {
  int target;
  int weight;
  int o;
};
struct vertice {
  long long time;
  int city;
  int edge_ID;
  int edge_W;
};
struct mysort {
  bool operator()(const vertice &l, const vertice &r) {
    if (l.time == r.time)
      return l.edge_W < r.edge_W;
    else
      return l.time < r.time;
  }
};
bool sort_pair(const pair<int, long long> &l, const pair<int, long long> &r) {
  return l.first < r.first;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<edge> > E(n + 1);
  for (int i = 0; i < m; i++) {
    edge a, b;
    cin >> a.target >> b.target >> a.weight;
    b.weight = a.weight;
    a.o = b.o = i + 1;
    E[a.target].push_back(b);
    E[b.target].push_back(a);
  }
  vertice v;
  cin >> v.city;
  v.time = 0;
  v.edge_ID = 0;
  v.edge_W = 0;
  vector<pair<int, long long> > used_edges;
  vector<int> visited(n + 1, 0);
  int counter = 0;
  multiset<vertice, mysort> S;
  S.insert(v);
  while (counter < n) {
    multiset<vertice, mysort>::iterator it = S.begin();
    if (visited[it->city] == 0) {
      visited[it->city] = 1;
      counter++;
      used_edges.push_back(pair<int, long long>(it->edge_ID, it->edge_W));
      for (int i = 0; i < E[it->city].size(); i++) {
        vertice c;
        c.time = it->time + E[it->city][i].weight;
        c.city = E[it->city][i].target;
        c.edge_ID = E[it->city][i].o;
        c.edge_W = E[it->city][i].weight;
        S.insert(c);
      }
    }
    S.erase(it);
  }
  sort(used_edges.begin(), used_edges.end(), sort_pair);
  long long ans = 0;
  for (int i = 1; i < used_edges.size(); i++) ans += used_edges[i].second;
  cout << ans << endl;
  for (int i = 1; i < used_edges.size(); i++)
    cout << used_edges[i].first << " ";
  cout << endl;
  return 0;
}
