#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
vector<pair<int, pair<long long, int> > > g[N];
bool vis[N];
void solve() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    g[u].push_back(make_pair(v, make_pair(c, i + 1)));
    g[v].push_back(make_pair(u, make_pair(c, i + 1)));
  }
  long long dis = 0;
  int s;
  cin >> s;
  priority_queue<pair<pair<long long, long long>, pair<int, int> > > q;
  q.push(make_pair(make_pair(0, 0), make_pair(s, 0)));
  vector<int> res;
  while (q.size() > 0) {
    pair<pair<long long, long long>, pair<int, int> > u = q.top();
    q.pop();
    if (vis[u.second.first]) continue;
    vis[u.second.first] = true;
    if (u.second.second > 0) res.push_back(u.second.second);
    dis -= u.first.second;
    for (int i = 0; i < g[u.second.first].size(); i++) {
      pair<int, pair<long long, int> > v = g[u.second.first][i];
      q.push(
          make_pair(make_pair(u.first.first - v.second.first, -v.second.first),
                    make_pair(v.first, v.second.second)));
    }
  }
  cout << dis << endl;
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] << ' ';
  }
  cout << endl;
}
int main() {
  solve();
  return 0;
}
