#include <bits/stdc++.h>
using namespace std;
int n, m, u;
struct node {
  int v;
  int w;
  int idx;
  long long d;
  node(int v, int w, int idx, long long d) : v(v), w(w), idx(idx), d(d) {}
  bool operator<(const node& o) const { return (d == o.d ? w > o.w : d > o.d); }
};
vector<node> edges[300010];
long long dis[300010];
long long pre[300010];
bool vis[300010];
long long tot;
vector<int> ans;
void solve() {
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    dis[i] = 1000000000000000LL;
  }
  dis[u] = 0;
  priority_queue<node> pq;
  pq.push(node(u, 0, 0, 0));
  while (!pq.empty()) {
    node tmp = pq.top();
    pq.pop();
    if (vis[tmp.v]) continue;
    vis[tmp.v] = true;
    tot += tmp.w;
    if (tmp.v != u) {
      ans.push_back(tmp.idx);
    }
    for (int i = 0; i < edges[tmp.v].size(); ++i) {
      node edg = edges[tmp.v][i];
      if (vis[edg.v]) continue;
      if (dis[edg.v] > tmp.d + edg.w) {
        dis[edg.v] = tmp.d + edg.w;
        pre[edg.v] = edg.w;
        pq.push(node(edg.v, edg.w, edg.idx, tmp.d + (long long)edg.w));
      } else if (dis[edg.v] == tmp.d + edg.w && edg.w < pre[edg.v]) {
        pq.push(node(edg.v, edg.w, edg.idx, tmp.d + (long long)edg.w));
      }
    }
  }
}
int main() {
  int a, b, w;
  while (cin >> n >> m) {
    for (int i = 1; i <= m; ++i) {
      cin >> a >> b >> w;
      edges[a].push_back(node(b, w, i, -1));
      edges[b].push_back(node(a, w, i, -1));
    }
    cin >> u;
    tot = 0LL;
    solve();
    cout << tot << endl;
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i];
      if (i < ans.size() - 1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }
  return 0;
}
