#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 5;
bool res[N];
bool vis[N];
struct edge {
  int f, to, w1;
  long long w2;
  int idx;
  bool operator<(const edge &e) const {
    if (w2 != e.w2) return w2 < e.w2;
    return w1 < e.w1;
  }
};
int n, m, u;
vector<multiset<edge>> g(N);
long long sm = 0;
void relax(edge &e) {
  for (auto &it : g[e.to]) {
    auto tmp = it;
    if (!vis[tmp.to]) {
      tmp.w2 += e.w2;
      g[u].insert(tmp);
    }
  }
}
void solve() {
  int edges = 0;
  vis[u] = 1;
  while (edges < n - 1) {
    edge tmp = *g[u].begin();
    g[u].erase(g[u].begin());
    if (vis[tmp.to]) continue;
    res[tmp.idx] = 1;
    vis[tmp.to] = 1;
    sm += tmp.w1;
    ++edges;
    relax(tmp);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int f, t, w;
    scanf("%d%d%d", &f, &t, &w);
    g[f].insert({f, t, w, w, i + 1});
    g[t].insert({t, f, w, w, i + 1});
  }
  scanf("%d", &u);
  solve();
  cout << sm << '\n';
  for (int i = 1; i <= m; ++i)
    if (res[i]) printf("%d ", i);
  return 0;
}
