#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long infinity = 1000000000000000000;   const int inf = 1e9 + 5;   bool do_debug = false;   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto element : v) {       os << element <<    ;     }     return os;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, pair<T, S>& p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, set<T>& v) {     if (v.size() == 0) {       os <<  empty set n ;       return os;     }     auto endit = v.end();     endit--;     os <<  [ ;     for (auto it = v.begin(); it != v.end(); it++) {       os << *it;       if (it != endit) {         os <<  ,  ;       }     }     os <<  ] ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, multiset<T>& v) {     if (v.size() == 0) {       os <<  empty multiset n ;       return os;     }     auto endit = v.end();     endit--;     os <<  [ ;     for (auto it = v.begin(); it != v.end(); it++) {       os << *it;       if (it != endit) {         os <<  ,  ;       }     }     os <<  ] ;     return os;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, map<T, S>& v) {     if (v.size() == 0) {       os <<  empty map n ;       return os;     }     auto endit = v.end();     endit--;     os <<  { ;     for (auto it = v.begin(); it != v.end(); it++) {       os <<  (  << (*it).first <<   :   << (*it).second <<  ) ;       if (it != endit) {         os <<  ,  ;       }     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, vector<vector<T>>& v) {     for (auto& subv : v) {       for (auto& e : subv) {         os << e <<    ;       }       os <<   n ;     }     return os;   }   const int maxn = 3e5 + 5;   int n_nodes, n_edges, target;   vector<vector<int>> adj;   vector<array<int, 4>> edges;   long long dist[maxn];   long long depth[maxn];   int incoming[maxn];   int added[maxn];   set<int> ans;   long long ans_w;   void dijkstra() {     int node = target;     priority_queue<pair<long long, long long>> pq;     pq.push(make_pair(0, target));     while (!pq.empty()) {       long long w = -pq.top().first;       node = pq.top().second;       pq.pop();       if (w > dist[node]) {         continue;       }       for (int e : adj[node]) {         int next = edges[e][1];         if (next == node) next = edges[e][2];         if (dist[node] + edges[e][0] < dist[next]) {           if (incoming[next] != -1) {             ans_w -= edges[incoming[next]][0];             ans.erase(incoming[next]);           }           incoming[next] = e;           ans_w += edges[incoming[next]][0];           ans.insert(incoming[next]);           dist[next] = dist[node] + edges[e][0];           pq.push(make_pair(-dist[next], next));         } else if (dist[node] + edges[e][0] == dist[next]) {           if (edges[e][0] < edges[incoming[next]][0]) {             ans_w -= edges[incoming[next]][0];             ans.erase(incoming[next]);             incoming[next] = e;             ans_w += edges[incoming[next]][0];             ans.insert(incoming[next]);           }         }       }     }   }   void mst() {     int node = target;     priority_queue<pair<long long, long long>> pq;     for (int e : adj[node]) {       int u = edges[e][1], v = edges[e][2];       if (u != node) swap(u, v);       depth[v] = edges[e][0];       incoming[v] = e;       ans_w += edges[e][0];       ans.insert(e);       pq.push(make_pair(-edges[e][0], v));     }     while (!pq.empty()) {       long long d = -pq.top().first;       node = pq.top().second;       pq.pop();       for (int e : adj[node]) {         long long w = edges[e][0];         int u = edges[e][1], v = edges[e][2];         if (u != node) swap(u, v);         if (depth[u] + w == dist[v]) {           if (incoming[v] == -1) {             ans_w += w;             ans.insert(e);             incoming[v] = e;           } else {             if (w < edges[incoming[v]][0]) {               ans_w -= edges[incoming[v]][0];               ans.erase(incoming[v]);               incoming[v] = e;               ans_w += edges[incoming[v]][0];               ans.insert(incoming[v]);             }           }           depth[v] = dist[v];         }       }     }   }   void solve() {     for (int i = 0; i < maxn; i++) {       incoming[i] = -1;       dist[i] = infinity;       depth[i] = infinity;       added[i] = 0;     }     cin >> n_nodes >> n_edges;     adj.resize(n_nodes);     for (int i = 0; i < n_edges; i++) {       int w, u, v;       cin >> u >> v >> w;       u--;       v--;       adj[u].push_back(i);       adj[v].push_back(i);       edges.push_back({w, u, v, i});     }     cin >> target;     target--;     dist[target] = 0;     depth[target] = 0;     ans_w = 0;     dijkstra();     cout << ans_w <<   n ;     for (int a : ans) {       cout << a + 1 <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int q = 1;     while (q-- > 0) {       solve();     }     return 0;   }