#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 10;
int n, m;
long long d[maxN];
int par[maxN], edge[maxN];
vector<pair<int, int> > adj[maxN];
void dijkstra(int source) {
  fill(d, d + maxN, 1e18);
  d[source] = 0;
  par[source] = -1;
  set<pair<int, int> > s;
  s.insert(make_pair(d[source], source));
  while (!s.empty()) {
    int v = s.begin()->second;
    s.erase(s.begin());
    for (int i = 0; i < adj[v].size(); i++) {
      int u = adj[v][i].first, edge_num = adj[v][i].second;
      int w = edge[edge_num];
      if (d[u] > d[v] + w) {
        s.erase(make_pair(d[u], u));
        d[u] = d[v] + w;
        par[u] = edge_num;
        s.insert(make_pair(d[u], u));
      } else if (d[u] == d[v] + w && edge[par[u]] > w)
        par[u] = edge_num;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u, w;
    cin >> v >> u >> w;
    adj[v].push_back(make_pair(u, i));
    adj[u].push_back(make_pair(v, i));
    edge[i] = w;
  }
  int source;
  cin >> source;
  dijkstra(source);
  vector<int> res;
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    if (par[i] != -1) ans += edge[par[i]], res.push_back(par[i]);
  sort(res.begin(), res.end());
  cout << ans << '\n';
  for (int i = 0; i < res.size(); i++) cout << res[i] + 1 << " ";
  cout << '\n';
  return 0;
}
