#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long mod = 1e18 + 9;
long long n, m, s;
int minv[maxn];
bool vis[maxn];
struct edge {
  int to, cost;
  int id;
  edge() {}
  edge(int id, int to, int cost) {
    this->id = id;
    this->to = to;
    this->cost = cost;
  }
};
int f[maxn], t[maxn], cc[maxn];
vector<edge> g[maxn];
long long dis[maxn];
void spfa() {
  vis[s] = 1;
  queue<int> que;
  que.push(s);
  for (int i = 1; i <= n; i++) dis[i] = mod;
  dis[s] = 0;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    vis[x] = 0;
    int len = g[x].size();
    for (int i = 0; i < len; i++) {
      int to = g[x][i].to;
      int cost = g[x][i].cost;
      int id = g[x][i].id;
      if (dis[to] > dis[x] + cost) {
        dis[to] = dis[x] + cost;
        minv[to] = id;
        if (!vis[to]) {
          que.push(to);
          vis[to] = 0;
        }
      } else if (dis[to] == dis[x] + cost && cost < cc[minv[to]]) {
        minv[to] = id;
      }
    }
  }
  return;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    cc[i] = c;
    g[a].push_back(edge(i, b, c));
    g[b].push_back(edge(i, a, c));
  }
  cin >> s;
  spfa();
  set<int> ss;
  for (int i = 1; i <= n; i++) {
    if (i == s) continue;
    ss.insert(minv[i]);
  }
  long long sum = 0;
  for (set<int>::iterator iter = ss.begin(); iter != ss.end(); iter++) {
    sum += cc[*iter];
  }
  cout << sum << endl;
  for (set<int>::iterator iter = ss.begin(); iter != ss.end(); iter++) {
    if ((*iter) == 0) continue;
    cout << (*iter) << ' ';
  }
  return 0;
}
