#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MAXN = 3000005;
vector<pair<int, int> > adj[MAXN];
vector<int> ids[MAXN];
int n;
vector<long long> dist;
int used[MAXN];
int mycost[MAXN];
struct mypair {
  long long first;
  int second;
  mypair(long long x, long long y) : first(x), second(y) {}
};
bool operator<(const mypair& m1, const mypair& m2) {
  if (m1.first < m2.first) return true;
  if (m1.first == m2.first) return m1.second < m2.second;
  return false;
}
void dijkstra(int s) {
  long long huge = INF;
  huge *= huge;
  dist.assign(n + 1, huge);
  set<mypair> q;
  dist[s] = 0LL;
  q.insert(mypair(0LL, s));
  while (!q.empty()) {
    mypair top = *q.begin();
    q.erase(q.begin());
    int v = top.second;
    long long d = top.first;
    for (int i = 0; i < (int)adj[v].size(); ++i) {
      int v2 = adj[v][i].second;
      int cost = adj[v][i].first;
      if (dist[v2] > dist[v] + cost ||
          ((dist[v2] == dist[v] + cost) &&
           (mycost[used[v2]] > mycost[ids[v][i]]))) {
        if (dist[v2] != huge) q.erase(q.find(mypair(dist[v2], v2)));
        dist[v2] = dist[v] + cost;
        used[v2] = ids[v][i];
        q.insert(mypair(dist[v2], v2));
      }
    }
  }
}
int main() {
  int m;
  while (scanf(" %d %d", &n, &m) != EOF) {
    for (int i = 0; i < n + 2; ++i) adj[i].clear(), ids[i].clear();
    for (int i = 0; i < m; ++i) {
      int u, v, w;
      scanf(" %d %d %d", &u, &v, &w);
      adj[u].push_back(pair<int, int>(w, v));
      adj[v].push_back(pair<int, int>(w, u));
      ids[u].push_back(i + 1);
      ids[v].push_back(i + 1);
      mycost[i + 1] = w;
    }
    int ini;
    scanf(" %d", &ini);
    for (int i = 0; i < n + 1; ++i) used[i] = -1;
    dijkstra(ini);
    long long res = 0LL;
    for (int i = 1; i < n + 1; ++i)
      if (used[i] != -1) res += mycost[used[i]];
    printf("%lld\n", res);
    for (int i = 1; i < n + 1; ++i)
      if (used[i] != -1) printf("%d ", used[i]);
    printf("\n");
  }
}
