#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long edge[300100], dist[300100], wt[300100];
bool visited[300100];
set<pair<long long, long long> > st;
vector<pair<pair<long long, long long>, long long> > g[300100];
void mst() {
  long long i, k;
  while (!st.empty()) {
    long long u = (*st.begin()).second;
    visited[u] = 1;
    st.erase(st.begin());
    k = g[u].size();
    for (i = 0; i < k; i++) {
      long long v = g[u][i].first.first;
      if (!visited[v] && dist[v] >= g[u][i].first.second + dist[u]) {
        if (dist[v] == g[u][i].first.second + dist[u] &&
            wt[edge[v]] <= wt[g[u][i].second])
          continue;
        st.erase(st.find(pair<long long, long long>(dist[v], v)));
        edge[v] = g[u][i].second;
        dist[v] = g[u][i].first.second + dist[u];
        st.insert(pair<long long, long long>(dist[v], v));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, m, i, j, k, l;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> j >> k >> l;
    wt[i + 1] = l;
    g[j].push_back(pair<pair<long long, long long>, long long>(
        pair<long long, long long>(k, l), i + 1));
    g[k].push_back(pair<pair<long long, long long>, long long>(
        pair<long long, long long>(j, l), i + 1));
  }
  for (i = 1; i <= n; i++) dist[i] = 1e18;
  cin >> j;
  dist[j] = 0;
  for (i = 1; i <= n; i++) st.insert(pair<long long, long long>(dist[i], i));
  edge[j] = INT_MAX;
  mst();
  for (i = 1; i <= n; i++)
    if (i != j) ans += wt[edge[i]];
  cout << ans << "\n";
  sort(edge + 1, edge + n + 1);
  for (i = 1; i < n; i++) cout << edge[i] << " ";
  cout << "\n";
  return 0;
}
