#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, w, st;
vector<int> g[300005], e[300005];
vector<int> id[300005];
queue<int> q;
int inq[300005], pre[300005], from[300005];
long long dis[300005], sum;
int lst[300005], tot = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back(v);
    e[u].push_back(w);
    id[u].push_back(i);
    g[v].push_back(u);
    e[v].push_back(w);
    id[v].push_back(i);
  }
  scanf("%d", &st);
  memset(dis, 0x3f, sizeof(dis));
  inq[st] = 1;
  dis[st] = 0LL;
  q.push(st);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    inq[u] = 0;
    for (int i = 0; i < g[u].size(); i++)
      if (dis[u] + (long long)e[u][i] < dis[g[u][i]]) {
        dis[g[u][i]] = dis[u] + (long long)e[u][i];
        pre[g[u][i]] = id[u][i];
        from[g[u][i]] = e[u][i];
        if (!inq[g[u][i]]) {
          inq[g[u][i]] = 1;
          q.push(g[u][i]);
        }
      } else if (dis[u] + (long long)e[u][i] == dis[g[u][i]] &&
                 e[u][i] < from[g[u][i]]) {
        pre[g[u][i]] = id[u][i];
        from[g[u][i]] = e[u][i];
      }
  }
  for (int i = 1; i <= n; i++) {
    if (i != st) {
      lst[++tot] = pre[i];
      sum += (long long)from[i];
    }
  }
  printf("%I64d\n", sum);
  for (int i = 1; i <= tot; i++) printf("%d ", lst[i]);
}
