#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
struct edge {
  int w, y, num;
};
int n, m, s;
vector<edge> d[MAXN];
int num[MAXN];
long long dist[MAXN];
int pr[MAXN];
long long ans = 0;
set<int> res;
inline edge make_edge(int y, int z, int num) {
  edge e;
  e.y = y, e.w = z, e.num = num;
  return e;
}
void dijkstra(int x) {
  priority_queue<pair<long long, int> > o;
  o.push(make_pair(0, x));
  while (!o.empty()) {
    x = o.top().second;
    long long y = o.top().first;
    o.pop();
    if (-y != dist[x]) continue;
    for (int i = 0; i < d[x].size(); i++) {
      int to = d[x][i].y;
      if (dist[to] > dist[x] + d[x][i].w) {
        dist[to] = dist[x] + d[x][i].w;
        pr[to] = d[x][i].num;
        o.push(make_pair(-dist[to], to));
      } else if (dist[to] == dist[x] + d[x][i].w)
        if (num[pr[to]] > d[x][i].w) pr[to] = d[x][i].num;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    d[x].push_back(make_edge(y, z, i));
    d[y].push_back(make_edge(x, z, i));
    num[i] = z;
  }
  cin >> s;
  memset(dist, 63, sizeof(dist));
  memset(pr, false, sizeof(pr));
  dist[s] = 0;
  dijkstra(s);
  for (int i = 1; i <= n; i++)
    if (i != s) {
      res.insert(pr[i]);
    }
  for (set<int>::iterator it = res.begin(); it != res.end(); it++) {
    int x = *it;
    ans += num[x];
  }
  cout << ans << endl;
  for (set<int>::iterator it = res.begin(); it != res.end(); it++) {
    cout << *it << " ";
  }
}
