#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     vector<vector<vector<long long>>> g(n);     vector<vector<long long>> store(m);     for (long long i = 0; i < m; i++) {       long long a, b, c;       cin >> a >> b >> c;       --a;       b--;       g[a].push_back({b, c});       g[b].push_back({a, c});       store[i] = {a, b, c};     }     long long s;     cin >> s;     s--;     vector<long long> d(n, LONG_LONG_MAX);     vector<long long> parent(n), dd(n, LONG_LONG_MAX);     for (long long i = 0; i < n; i++) {       parent[i] = i;     }     d[s] = dd[s] = 0;     set<pair<long long, long long>> q;     q.insert({d[s], s});     while (!q.empty()) {       long long v = q.begin()->second;       q.erase(q.begin());       for (long long i = 0; i < g[v].size(); i++) {         long long to = g[v][i][0], len = g[v][i][1];         if (d[v] + len < d[to]) {           if (q.find({d[to], to}) != q.end()) {             q.erase({d[to], to});           }           parent[to] = v;           d[to] = d[v] + len;           dd[to] = len;           q.insert(make_pair(d[to], to));         } else if (d[v] + len == d[to]) {           if (dd[to] > len) {             dd[to] = len;             parent[to] = v;           }         }       }     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       ans += dd[i];     }     cout << ans << endl;     for (long long i = 0; i < m; i++) {       long long a = store[i][0];       long long b = store[i][1];       if (parent[a] == b || parent[b] == a) {         cout << i + 1 <<    ;       }     }     return 0;   }   