#include <bits/stdc++.h>
using namespace std;
const int ms = 312345;
const long long inf = 1e18;
long long parent[ms];
long long dist[ms];
map<pair<long long, long long>, long long> edges;
vector<pair<long long, long long>> adj[ms];
long long edgesUsed[ms];
set<long long> chosenEdges;
long long tt;
void dijkstra(long long v, long long total) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      heap;
  for (int i = 1; i <= total; ++i) {
    dist[i] = inf;
    parent[i] = -1;
  }
  for (int i = 1; i <= total; ++i) {
    edgesUsed[i] = inf;
  }
  heap.push({0, v});
  dist[v] = 0;
  edgesUsed[v] = 0;
  while (!heap.empty()) {
    pair<long long, long long> x = heap.top();
    heap.pop();
    long long vertex = x.second;
    for (auto k : adj[vertex]) {
      long long to = k.second;
      long long w = k.first;
      if (dist[to] > dist[vertex] + w) {
        dist[to] = dist[vertex] + w;
        edgesUsed[to] = w;
        parent[to] = vertex;
        heap.push({dist[to], to});
      } else if (dist[to] == dist[vertex] + w) {
        if (edgesUsed[to] > w) {
          edgesUsed[to] = w;
          parent[to] = vertex;
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed;
  cout << setprecision(15);
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    long long a, b;
    long long w;
    cin >> a >> b >> w;
    edges[{min(a, b), max(a, b)}] = i + 1;
    adj[a].push_back({w, b});
    adj[b].push_back({w, a});
  }
  long long start;
  cin >> start;
  dijkstra(start, n);
  tt = 0;
  for (int i = 1; i <= n; ++i) {
    tt += edgesUsed[i];
  }
  cout << tt << endl;
  for (auto k : edges) {
    pair<long long, long long> x = k.first;
    if (parent[x.first] == x.second || parent[x.second] == x.first)
      chosenEdges.insert(k.second);
  }
  for (auto x : chosenEdges) {
    cout << x << ' ';
  }
  cout << endl;
  return 0;
}
