#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int INF = 0x3f3f3f3f;
struct edge {
  int u, v, w, id, b;
} e[N];
vector<edge> adj[N];
long long dist[N];
int last[N];
int main() {
  int n, m, u, v, w, s;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back((edge){u, v, w, i, 0});
    adj[v].push_back((edge){v, u, w, i, 0});
    e[i] = (edge){u, v, w, i, 0};
  }
  scanf("%d", &s);
  memset((dist), (INF), sizeof(dist));
  memset((last), (-1), sizeof(last));
  dist[s] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    pair<long long, int> p = q.top();
    q.pop();
    int u = p.second;
    if (dist[u] < p.first) continue;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].v, w = adj[u][i].w;
      if (dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        if (last[v] != -1) e[last[v]].b = 0;
        last[v] = adj[u][i].id;
        e[last[v]].b = 1;
        q.push(make_pair(dist[v], v));
      } else if (dist[v] == dist[u] + w && e[last[v]].w > w) {
        if (last[v] != -1) e[last[v]].b = 0;
        last[v] = adj[u][i].id;
        e[last[v]].b = 1;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= m; i++)
    if (e[i].b) ans += e[i].w;
  printf("%lld\n", ans);
  for (int i = 1; i <= m; i++)
    if (e[i].b) printf("%d ", i);
  return 0;
}
