#include <bits/stdc++.h>
using namespace std;
int n, m, u;
long long res;
vector<pair<pair<int, int>, int> > adj[300001];
vector<long long> d(300001, 1000000000000000000),
    maxPar(300001, 1000000000000000000);
int parent[300001];
stack<int> result;
void dijkstra() {
  d[u] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      pq;
  pq.push(make_pair(0, u));
  while (!pq.empty()) {
    pair<long long, int> temp = pq.top();
    pq.pop();
    long long dist = temp.first;
    int node = temp.second;
    if (dist > d[node]) continue;
    for (int i = 0; i < adj[node].size(); i++) {
      pair<int, int> v = adj[node][i].first;
      if (d[node] + v.second < d[v.first]) {
        d[v.first] = d[node] + v.second;
        pq.push(make_pair(d[v.first], v.first));
        parent[v.first] = node;
        maxPar[v.first] = v.second;
      } else if (d[node] + v.second == d[v.first] && v.second < maxPar[v.first])
        parent[v.first] = node, maxPar[v.first] = v.second;
    }
  }
}
void solve() {
  for (int i = 1; i <= n; i++) {
    if (i == u) continue;
    bool stop = 0;
    for (int j = 0; j < adj[i].size() && !stop; j++) {
      if (parent[i] == adj[i][j].first.first)
        res += (long long)adj[i][j].first.second, result.push(adj[i][j].second);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    adj[a].push_back(make_pair(pair<int, int>(b, c), i + 1));
    adj[b].push_back(make_pair(pair<int, int>(a, c), i + 1));
  }
  scanf("%d", &u);
  dijkstra();
  solve();
  printf("%I64d\n", res);
  while (!result.empty()) {
    printf("%d ", result.top());
    result.pop();
  }
  return 0;
}
