#include <bits/stdc++.h>
using namespace std;
struct data {
  int v;
  long long w;
  data(int a, long long b) {
    v = a;
    w = b;
  }
  bool operator<(const data& p) const { return w > p.w; }
};
map<pair<int, int>, pair<int, long long> > mp;
vector<data> adj[300005];
long long dis[300005];
int node, edge;
priority_queue<data> qu;
void func(int u) {
  for (int i = 0; i <= node; i++) dis[i] = 500000000000000000ll;
  dis[u] = 0ll;
  while (!qu.empty()) qu.pop();
  qu.push(data(u, 0ll));
  while (!qu.empty()) {
    int u = qu.top().v;
    long long w = qu.top().w;
    qu.pop();
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].v;
      long long tw = adj[u][i].w + w;
      if (dis[v] > tw) {
        dis[v] = tw;
        qu.push(data(v, tw));
      }
    }
  }
}
vector<int> res;
int main() {
  scanf("%d%d", &node, &edge);
  for (int i = 1; i <= edge; i++) {
    int u, v;
    long long w;
    scanf("%d %d %I64d", &u, &v, &w);
    adj[u].push_back(data(v, w));
    adj[v].push_back(data(u, w));
    mp[make_pair(u, v)] = make_pair(i, w);
    mp[make_pair(v, u)] = make_pair(i, w);
  }
  int u;
  scanf("%d", &u);
  func(u);
  long long total = 0;
  for (int i = 1; i <= node; i++) {
    int u = -1;
    long long w = 500000000000000000ll;
    for (int j = 0; j < adj[i].size(); j++) {
      long long tw = adj[i][j].w;
      int v = adj[i][j].v;
      if (dis[v] + tw == dis[i] && w > tw) {
        w = tw;
        u = v;
      }
    }
    if (u != -1) {
      res.push_back(mp[make_pair(i, u)].first);
      total += mp[make_pair(i, u)].second;
    }
  }
  sort(res.begin(), res.end());
  printf("%I64d\n", total);
  for (int i = 0; i < res.size(); i++) printf("%d ", res[i]);
  return 0;
}
