#include <bits/stdc++.h>
using namespace std;
const long long int INF = 987654321098765;
vector<pair<long long int, pair<long long int, long long int> > > adj[300003];
long long int dist[300003];
bool visited[300003];
void dijkstra(int s) {
  memset(dist, INF, sizeof(dist));
  memset(visited, false, sizeof(visited));
  dist[s] = 0;
  priority_queue<pair<long long int, long long int>,
                 std::vector<pair<long long int, long long int> >,
                 std::greater<pair<long long int, long long int> > >
      pq;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    pair<long long int, long long int> node = pq.top();
    pq.pop();
    long long int d = node.first;
    long long int u = node.second;
    if (visited[u]) continue;
    visited[u] = true;
    for (int i = 0; i < adj[u].size(); i++) {
      long long int v = adj[u][i].first;
      long long int wt = adj[u][i].second.first;
      if (!visited[v] && wt + dist[u] < dist[v]) {
        dist[v] = wt + dist[u];
        pq.push(make_pair(dist[v], v));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, x, y, z, s;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    adj[x].push_back(make_pair(y, make_pair(z, i)));
    adj[y].push_back(make_pair(x, make_pair(z, i)));
  }
  cin >> s;
  dijkstra(s);
  long long int ans = 0;
  vector<long long int> edges;
  for (int u = 1; u <= n; u++) {
    if (u == s) continue;
    long long int minm = INT_MAX;
    long long int idx;
    for (int i = 0; i < adj[u].size(); i++) {
      long long int v = adj[u][i].first;
      long long int wt = adj[u][i].second.first;
      if (dist[v] + wt == dist[u]) {
        if (wt < minm) {
          minm = wt;
          idx = adj[u][i].second.second;
        }
      }
    }
    ans += minm;
    edges.push_back(idx);
  }
  cout << ans << "\n";
  for (int i = 0; i < edges.size(); i++) {
    cout << edges[i] << " ";
  }
  cout << "\n";
  return 0;
}
