#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, int> > adj[300005], ne[300010];
priority_queue<pair<long long, int> > pq;
long long dis[300005];
int flag[300005];
map<pair<int, int>, int> mp;
vector<int> an;
int main() {
  int n, m, u;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) dis[i] = 1ll << 60;
  for (int i = 1; i <= m; i++) {
    int x, y;
    long long w;
    scanf("%d %d %lld", &x, &y, &w);
    adj[x].push_back(pair<long long, int>(w, y));
    adj[y].push_back(pair<long long, int>(w, x));
    mp[make_pair(x, y)] = i;
    mp[make_pair(y, x)] = i;
  }
  scanf("%d", &u);
  pq.push(pair<long long, int>(0, u));
  dis[u] = 0;
  while (!pq.empty()) {
    int x = pq.top().second;
    pq.pop();
    if (flag[x]) continue;
    flag[x] = 1;
    for (pair<long long, int> p : adj[x]) {
      long long w = p.first;
      int y = p.second;
      if (dis[y] > dis[x] + w) {
        dis[y] = dis[x] + w;
        pq.push(pair<long long, int>(-dis[y], y));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < adj[i].size(); j++) {
      int x = i;
      int y = adj[i][j].second;
      long long w = adj[i][j].first;
      if (dis[x] > dis[y]) swap(x, y);
      if (dis[y] - dis[x] == w) ne[y].push_back(pair<long long, int>(w, x));
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (ne[i].size() == 0) continue;
    sort(ne[i].begin(), ne[i].end());
    ans += ne[i][0].first;
    an.push_back(mp[make_pair(i, ne[i][0].second)]);
  }
  printf("%lld\n", ans);
  for (int x : an) printf("%d ", x);
  puts("");
  return 0;
}
