#include <bits/stdc++.h>
using namespace std;
int n, m, S;
long long dis[300000 + 2];
int pre[300000 + 2];
bool vis[300000 + 2];
struct edge {
  int from, to, dis;
};
vector<edge> E;
vector<int> G[300000 + 2];
vector<int> result;
void addedge(int from, int to, int dis) {
  E.push_back((edge){from, to, dis});
  E.push_back((edge){to, from, dis});
  G[from].push_back((E).size() - 2);
  G[to].push_back((E).size() - 1);
}
void SPFA() {
  for (int i = 1; i <= n; i++) dis[i] = 0x7fffffffffffffff, vis[i] = 0;
  dis[S] = 0, vis[S] = 1;
  queue<int> Q;
  Q.push(S);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    vis[x] = 0;
    for (int i = 0; i < (G[x]).size(); ++i) {
      edge &e = E[G[x][i]];
      if (dis[e.to] > dis[e.from] + e.dis) {
        dis[e.to] = dis[e.from] + e.dis;
        pre[e.to] = G[x][i];
        if (!vis[e.to]) Q.push(e.to), vis[e.to] = 1;
      } else if (dis[e.to] == dis[e.from] + e.dis) {
        if (E[pre[e.to]].dis > e.dis) pre[e.to] = G[x][i];
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (i != S) ans += E[pre[i]].dis;
  printf("%I64d\n", ans);
  result.clear();
  for (int i = 1; i <= n; i++)
    if (i != S) result.push_back(pre[i]);
  sort(result.begin(), result.end());
  for (int i = 0; i < n - 1; ++i)
    printf("%d ",
           (result[i] & 1) ? (result[i] - 1) / 2 + 1 : result[i] / 2 + 1);
  printf("\n");
}
void init() {
  for (int i = 1; i <= n; i++) G[i].clear();
  E.clear();
}
void solve() {
  init();
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    addedge(a, b, c);
  }
  scanf("%d", &S);
  SPFA();
}
int main() {
  while (~scanf("%d%d", &n, &m)) solve();
  return 0;
}
