#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<long long, int> > > v[300010];
vector<pair<int, pair<int, long long> > > vv;
vector<int> ans;
set<pair<long long, pair<int, int> > > s;
int parents[300010];
long long value[300010];
int edges[300010];
int main() {
  int n, m, i, x, y;
  long long a, z = 0;
  ;
  set<pair<long long, pair<int, int> > >::iterator it;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    scanf("%d%d%lld", &x, &y, &a);
    v[x].push_back(make_pair(y, make_pair(a, i)));
    v[y].push_back(make_pair(x, make_pair(a, i)));
    vv.push_back(make_pair(x, make_pair(y, a)));
  }
  cin >> z;
  parents[z] = -1;
  s.insert(make_pair(0, make_pair(z, -1)));
  z = 0;
  while (!s.empty()) {
    it = s.begin();
    a = (*it).first;
    x = (*it).second.first;
    y = (*it).second.second;
    if (y != -1) ans.push_back(y);
    s.erase(s.begin());
    for (i = 0; i < v[x].size(); i++) {
      if (parents[v[x][i].first] == 0) {
        parents[v[x][i].first] = x;
        value[v[x][i].first] = a + v[x][i].second.first;
        edges[v[x][i].first] = v[x][i].second.second;
        s.insert(make_pair(a + v[x][i].second.first,
                           make_pair(v[x][i].first, v[x][i].second.second)));
      } else if (value[v[x][i].first] > (a + v[x][i].second.first)) {
        it = s.find(make_pair(value[v[x][i].first],
                              make_pair(v[x][i].first, edges[v[x][i].first])));
        s.erase(it);
        parents[v[x][i].first] = x;
        value[v[x][i].first] = a + v[x][i].second.first;
        edges[v[x][i].first] = v[x][i].second.second;
        s.insert(make_pair(a + v[x][i].second.first,
                           make_pair(v[x][i].first, v[x][i].second.second)));
      } else if (value[v[x][i].first] == (a + v[x][i].second.first)) {
        y = edges[v[x][i].first];
        if (vv[y].second.second > vv[v[x][i].second.second].second.second) {
          it =
              s.find(make_pair(value[v[x][i].first],
                               make_pair(v[x][i].first, edges[v[x][i].first])));
          s.erase(it);
          parents[v[x][i].first] = x;
          value[v[x][i].first] = a + v[x][i].second.first;
          edges[v[x][i].first] = v[x][i].second.second;
          s.insert(make_pair(a + v[x][i].second.first,
                             make_pair(v[x][i].first, v[x][i].second.second)));
        }
      }
    }
  }
  for (i = 0; i < ans.size(); i++) z += vv[ans[i]].second.second;
  cout << z << "\n";
  for (i = 0; i < ans.size(); i++) printf("%d ", ans[i] + 1);
  printf("\n");
  return 0;
}
