#include <bits/stdc++.h>

using namespace std;

#define N 1000000
long long best[N], p[N], w[N], connector[N];
vector<pair<int, int>> ln[N];
map<pair<int, int>, int> index;

void link(int a, int b, int c) {
  ln[a].push_back({b, c});
}

struct INFO {
  long long cost, connector;
  int dest, parent;
};

bool operator<(const INFO& a, const INFO& b) {
  return a.cost < b.cost ||
    (a.cost == b.cost && a.connector < b.connector);
}

bool operator>(const INFO& a, const INFO& b) {
  return !(operator<(a, b));
}

void dijkstra(int n) {
  priority_queue<INFO, vector<INFO>, greater<INFO>> q;
  q.push({0, 0, n, -1});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cost = t.cost;
    int v = t.dest;
    //~ if (cost < best[v] || (cost == best[v] && connector[v] > t.connector)) {
    if (cost < best[v] || (best[t.parent] + t.connector < best[v])) {
      best[v] = cost;
      connector[v] = t.connector;
      p[v] = t.parent;
      for (auto e: ln[v]) {
        q.push({best[v] + e.second, e.second, e.first, v});
      }
    }
  }
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[i] = c;
    index[{a, b}] = i;
    index[{b, a}] = i;
    link(a, b, c);
    link(b, a, c);
  }

  for (int i = 0; i < n; i++) {
    best[i] = 1e17l;
  }
  int u; cin >> u; u--;
  dijkstra(u);

  //~ for (int i = 0; i < n; i++) {
    //~ cout << p[i] << ' ';
  //~ }

  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;
    int e = index[{i, p[i]}];
    ans += w[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 3123123
vector<pair<int, int>> ln[N];
long long SP[N], W, cost[N];
int parent[N];

struct Edge { int w, u, v; };

bool operator< (const Edge& a, const Edge& b) { return a.w < b.w; }

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<Edge> E;
  for (int i = 0; i < m; i++) {
    int u, v, w; cin >> u >> v >> w; u--; v--;
    E.push_back({w, u, v});
    ln[u].push_back({v, w});
    ln[v].push_back({u, w});
  }

  int root; cin >> root; root--;
  fill(SP, SP + N, 1ll << 60);
  SP[root] = 0;
  set<pair<long long, int>> S;
  S.insert({0ll, root});
  while (!S.empty()) {
    int v = S.begin()->second;
    S.erase(S.begin());
    for (auto e: ln[v]) {
      if (SP[v] + e.second < SP[e.first]) {
        S.erase({e.first, SP[e.first]});
        S.insert({SP[v] + e.second, e.first});
        SP[e.first] = SP[v] + e.second;
      }
    }
  }

  fill(cost, cost + N, 1ll << 60);
  for (int i = 0; i < n; i++) {
    if (i == root) continue;
    for (auto e: ln[i]) {
      if (SP[e.first] + e.second == SP[i] && e.second < cost[i]) {
        cost[i] = e.second;
        parent[i] = e.first;
      }
    }
  }

  vector<int> answer;
  for (int i = 0; i < m; i++) {
    if (SP[E[i].u] > SP[E[i].v]) swap(E[i].u, E[i].v);
    if (E[i].v != root && parent[E[i].v] == E[i].u) {
      W += E[i].w;
      answer.push_back(i + 1);
    }
  }

  cout << W << endl;
  for (auto e: answer) cout << e << ' ';

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 3123123
vector<pair<int, int>> ln[N];
long long SP[N];
bool printed[N];
int parent[N];

struct Edge { int w, u, v; };

bool operator< (const Edge& a, const Edge& b) { return a.w < b.w; }

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<Edge> E;
  for (int i = 0; i < m; i++) {
    int u, v, w; cin >> u >> v >> w; u--; v--;
    E.push_back({w, u, v});
    ln[u].push_back({v, w});
    ln[v].push_back({u, w});
  }

  int root; cin >> root; root--;
  fill(SP, SP + N, 1ll << 60);
  SP[root] = 0;
  set<pair<long long, int>> S;
  S.insert({0ll, root});
  while (!S.empty()) {
    int v = S.begin()->second;
    S.erase(S.begin());
    for (auto e: ln[v]) {
      if (SP[v] + e.second < SP[e.first]) {
        S.erase({e.first, SP[e.first]});
        S.insert({SP[v] + e.second, e.first});
        SP[e.first] = SP[v] + e.second;
      }
    }
  }

  auto ECP = E;
  sort(ECP.begin(), ECP.end());
  reverse(ECP.begin(), ECP.end());
  for (int i = 0; i < ECP.size(); i++) {
    Edge e = ECP[i];
    if (SP[e.u] > SP[e.v]) swap(e.u, e.v);
    if (SP[e.v] == e.w + SP[e.u]) parent[e.v] = e.u;
  }
  parent[root] = -1;

  long long W = 0;
  vector<int> answer;
  for (int i = 0; i < m; i++) {
    if (parent[E[i].u] == E[i].v || parent[E[i].v] == E[i].u) { W += E[i].w; answer.push_back(i + 1); }
  }

  cout << W << endl;
  for (auto e: answer) cout << e << ' ';

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
long long best[N], p[N], w[N], connector[N];
vector<pair<int, int>> ln[N];
map<pair<int, int>, int> index;

void link(int a, int b, int c) {
  ln[a].push_back({b, c});
}

struct INFO {
  long long cost, connector;
  int dest;
};

bool operator<(const INFO& a, const INFO& b) {
  return a.cost < b.cost ||
    (a.cost == b.cost && a.connector < b.connector);
}

bool operator>(const INFO& a, const INFO& b) {
  return !(operator<(a, b));
}

void dijkstra(int n) {
  priority_queue<INFO, vector<INFO>, greater<INFO>> q;
  q.push({0, 0, n});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cn = t.dest;
    int c = best[cn];
    for (auto e: ln[cn]) {
      int nc = c + e.second;
      if (best[e.first] > nc || (best[e.first] == nc && connector[e.first] > e.second)) {
        int v = e.first;
        p[v] = cn;
        connector[v] = e.second;
        best[v] = nc;
        q.push({nc, e.second, v});
      }
    }
  }
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[i] = c;
    index[{a, b}] = i;
    index[{b, a}] = i;
    link(a, b, c);
    link(b, a, c);
  }

  for (int i = 0; i < n; i++) {
    best[i] = 1e17l;
  }
  int u; cin >> u; u--;
  best[u] = 0;
  connector[u] = 0;
  p[u] = -1;
  dijkstra(u);

  //~ for (int i = 0; i < n; i++) {
    //~ cout << p[i] << ' ';
  //~ }

  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;
    int e = index[{i, p[i]}];
    ans += w[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  #if defined EHSANOO
  freopen("input", "r", stdin);
  #endif

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = 0;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  long long ans = 0;
  vector<int> v; v.reserve(n);
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    if (seen[nd]) continue;
    seen[nd] = true;
    if (parent[nd] != -1) {
      ans += connector[nd];
      v.push_back(ind[{nd, parent[nd]}] + 1);
    }
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] > e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  //~ for (int i = 0; i < n; i++) {
    //~ cout << parent[i] + 1 << ' ';
  //~ }
  //~ cout << endl;

  cout << ans << endl;
  if (v.size() != n - 1) {
    cout << "ERROR" << endl;
    exit(1);
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <cstdio>
#include <vector>
#include <set>

using namespace std;

#define N 3123123
vector<pair<int, int>> ln[N];
long long SP[N], W, cost[N];
int parent[N];

struct Edge { int w, u, v; };

int next_int() {
  char c = getchar();
  while (c < '0') c = getchar();
  long long v = c - '0';
  while (true) {
    c = getchar();
    if (c >= '0') {
      v *= 10;
      v += c - '0';
      continue;
    }
    break;
  }
  return v;
}

int main() {
  int n = next_int(), m = next_int();
  vector<Edge> E;
  for (int i = 0; i < m; i++) {
    int u = next_int() - 1, v = next_int() - 1, w = next_int();
    E.push_back({w, u, v});
    ln[u].push_back({v, w});
    ln[v].push_back({u, w});
  }

  int root = next_int() - 1;
  fill(SP, SP + N, 1ll << 60);
  SP[root] = 0;
  set<pair<long long, int>> S;
  S.insert({0ll, root});
  while (!S.empty()) {
    int v = S.begin()->second;
    S.erase(S.begin());
    for (auto e: ln[v]) {
      if (SP[v] + e.second < SP[e.first]) {
        S.erase({SP[e.first], e.first});
        S.insert({SP[v] + e.second, e.first});
        SP[e.first] = SP[v] + e.second;
      }
    }
  }

  fill(cost, cost + N, 1ll << 60);
  for (int i = 0; i < n; i++) {
    if (i == root) continue;
    for (auto e: ln[i]) {
      if (SP[e.first] + e.second == SP[i] && e.second < cost[i]) {
        cost[i] = e.second;
        parent[i] = e.first;
      }
    }
  }

  vector<int> answer;
  for (int i = 0; i < m; i++) {
    if (SP[E[i].u] > SP[E[i].v]) swap(E[i].u, E[i].v);
    if (E[i].v != root && parent[E[i].v] == E[i].u) {
      W += E[i].w;
      answer.push_back(i + 1);
    }
  }

  printf("%lld\n", W);
  for (auto e: answer) printf("%d ", e);

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = 0;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  long long ans = 0;
  vector<int> v; v.reserve(n);
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    if (seen[nd]) continue;
    seen[nd] = true;
    if (parent[nd] != -1) {
      ans += best[nd] - best[parent[nd]];
      v.push_back(ind[{nd, parent[nd]}] + 1);
    }
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] > e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 3123123
vector<pair<int, int>> ln[N];
long long SP[N], W, cost[N];
int parent[N];

struct Edge { int w, u, v; };

bool operator< (const Edge& a, const Edge& b) { return a.w < b.w; }

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<Edge> E;
  for (int i = 0; i < m; i++) {
    int u, v, w; cin >> u >> v >> w; u--; v--;
    E.push_back({w, u, v});
    ln[u].push_back({v, w});
    ln[v].push_back({u, w});
  }

  int root; cin >> root; root--;
  fill(SP, SP + N, 1ll << 60);
  SP[root] = 0;
  set<pair<long long, int>> S;
  S.insert({0ll, root});
  while (!S.empty()) {
    int v = S.begin()->second;
    S.erase(S.begin());
    for (auto e: ln[v]) {
      if (SP[v] + e.second < SP[e.first]) {
        S.erase({SP[e.first], e.first});
        S.insert({SP[v] + e.second, e.first});
        SP[e.first] = SP[v] + e.second;
      }
    }
  }

  fill(cost, cost + N, 1ll << 60);
  for (int i = 0; i < n; i++) {
    if (i == root) continue;
    for (auto e: ln[i]) {
      if (SP[e.first] + e.second == SP[i] && e.second < cost[i]) {
        cost[i] = e.second;
        parent[i] = e.first;
      }
    }
  }

  vector<int> answer;
  for (int i = 0; i < m; i++) {
    if (SP[E[i].u] > SP[E[i].v]) swap(E[i].u, E[i].v);
    if (E[i].v != root && parent[E[i].v] == E[i].u) {
      W += E[i].w;
      answer.push_back(i + 1);
    }
  }

  cout << W << endl;
  for (auto e: answer) cout << e << ' ';

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  #if defined EHSANOO
  freopen("input", "r", stdin);
  #endif

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = INF;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] >= e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
        q.push({-nc, dest});
      }
    }
  }

  //~ for (int i = 0; i < n; i++) {
    //~ cout << parent[i] + 1 << ' ';
  //~ }
  //~ cout << endl;
  //~
  //~ for (int i = 0; i < n; i++) {
    //~ cout << connector[i] << ' ';
  //~ }
  //~ cout << endl;

  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (parent[i] == -1) continue;
    v.push_back(ind[{i, parent[i]}] + 1);
  }

  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += weight[v[i] - 1];
  }

  cout << ans << endl;
  if (v.size() != n - 1) {
    cout << "ERROR" << endl;
    exit(1);
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }
  cout << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
long long best[N], p[N], w[N];
vector<pair<int, int>> ln[N];
map<pair<int, int>, int> index;

void link(int a, int b, int c) {
  ln[a].push_back({b, c});
}

void dfs(int n) {
  for (auto& e: ln[n]) {
    int v = e.first;
    long long cost = best[n] + (long long)e.second;
    if (cost <= best[v]) {
      best[v] = cost;
      p[v] = n;
      dfs(v);
    }
  }
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[i] = c;
    index[{a, b}] = i;
    index[{b, a}] = i;
    link(a, b, c);
    link(b, a, c);
  }

  for (int i = 0; i < n; i++) {
    best[i] = 1e17l;
  }
  int u; cin >> u; u--;
  best[u] = 0l;
  p[u] = -1;
  dfs(u); // Dijkstra?

  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;
    int e = index[{i, p[i]}];
    ans += w[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = 0;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  long long ans = 0;
  vector<int> v; v.reserve(n);
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    if (seen[nd]) continue;
    seen[nd] = true;
    if (parent[nd] != -1) {
      ans += weight[ind[{nd, parent[nd]}]];
      v.push_back(ind[{nd, parent[nd]}] + 1);
    }
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] > e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
long long best[N], p[N], w[N], connector[N];
vector<pair<int, int>> ln[N];
map<pair<int, int>, int> index;

void link(int a, int b, int c) {
  ln[a].push_back({b, c});
}

void dfs(int n) {
  for (auto& e: ln[n]) {
    int v = e.first;
    long long cost = best[n] + (long long)e.second;
    if (cost < best[v] || (cost == best[v] && connector[v] > e.second)) {
      best[v] = cost;
      connector[v] = e.second;
      p[v] = n;
      dfs(v);
    }
  }
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[i] = c;
    index[{a, b}] = i;
    index[{b, a}] = i;
    link(a, b, c);
    link(b, a, c);
  }

  for (int i = 0; i < n; i++) {
    best[i] = 1e17l;
  }
  int u; cin >> u; u--;
  best[u] = 0l;
  p[u] = -1;
  dfs(u); // Dijkstra?

  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;
    int e = index[{i, p[i]}];
    ans += w[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long sp[1000000];
int p[1000000];
int n, m;
vector<pair<long long, long long>> links[1000000];
map<pair<long long, long long> , int> mp;

void dfs(int n) {
  //~ cout << "DFS: " << n << endl;
  for (auto& e: links[n]) {
    //~ cout << "TESTING " << e.first << endl;
    int v = e.first;
    int nc = sp[n] + e.second;
    if (sp[v] > nc) {
      sp[v] = nc;
      p[v] = n;
      dfs(v);
    }
  }
}

int weight[1000000];
int main() { ios_base::sync_with_stdio(false);
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    links[a - 1].push_back({b - 1, c});
    links[b - 1].push_back({a - 1, c});
    mp[{a - 1, b - 1}] = mp[{b - 1, a - 1}] = i + 1;
    weight[i + 1] = c;
  }

  int u;
  cin >> u;
  u--;

  for (int i = 0; i < n; i++) {
    sp[i] = 999999999999999l;
  }
  sp[u] = 0;
  p[u] = -1;
  dfs(u);

  //~ for (int i = 0; i < n; i++) {
    //~ cout << p[i] << ' ';
  //~ }

  long long ans = 0;
  set<int> ansv;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;

    int e = mp[{i, p[i]}];
    if (ansv.find(e) != ansv.end()) continue;
    ansv.insert(e);
    ans += weight[e];
  }

  cout << ans << endl;
  for (auto e: ansv) cout << e << ' ';

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  #if defined EHSANOO
  freopen("input", "r", stdin);
  #endif

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = INF;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] >= e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  //~ for (int i = 0; i < n; i++) {
    //~ cout << parent[i] + 1 << ' ';
  //~ }
  //~ cout << endl;
  //~
  //~ for (int i = 0; i < n; i++) {
    //~ cout << connector[i] << ' ';
  //~ }
  //~ cout << endl;

  vector<int> v;
  v.reserve(n + 10);
  for (int i = 0; i < n; i++) {
    if (parent[i] == -1) continue;
    v.push_back(ind[{i, parent[i]}] + 1);
  }

  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += weight[v[i] - 1];
  }

  cout << ans << endl;
  if (v.size() != n - 1) {
    cout << "ERROR" << v.size() << endl;
    exit(1);
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }
  cout << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  #if defined EHSANOO
  freopen("input", "r", stdin);
  #endif

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = INF;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] >= e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  //~ for (int i = 0; i < n; i++) {
    //~ cout << parent[i] + 1 << ' ';
  //~ }
  //~ cout << endl;
  //~
  //~ for (int i = 0; i < n; i++) {
    //~ cout << connector[i] << ' ';
  //~ }
  //~ cout << endl;

  vector<int> v;
  v.reserve(n + 10);
  for (int i = 0; i < n; i++) {
    if (parent[i] == -1) continue;
    v.push_back(ind[{i, parent[i]}] + 1);
  }

  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += weight[v[i] - 1];
  }

  cout << ans << endl;
  if (v.size() != n - 1) {
    cout << "ERROR" << endl;
    exit(1);
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }
  cout << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  #if defined EHSANOO
  freopen("input", "r", stdin);
  #endif

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = 0;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  long long ans = 0;
  vector<int> v; v.reserve(n);
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    if (seen[nd]) continue;
    seen[nd] = true;
    if (parent[nd] != -1) {
      ans += connector[nd];
      v.push_back(ind[{nd, parent[nd]}] + 1);
    }
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] > e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  //~ for (int i = 0; i < n; i++) {
    //~ cout << parent[i] + 1 << ' ';
  //~ }
  //~ cout << endl;

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N];
bool seen[N];
int parent[N];

void link(int i, int j, long long cost) {
  ln[i].push_back({j, cost});
}

void index(int x, int y, int i) {
  ind[{x, y}] = ind[{y, x}] = i;
}

int getindex(int i, int j) {
  return ind[{i, j}];
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    link(--a, --b, c);
    link(b, a, c);
    index(a, b, i);
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  #define _T pair<pair<long long, long long>, pair<int, int>>
  priority_queue<_T, vector<_T>, greater<_T>> dijq;
  dijq.push({{0, 0}, {u, -1}});
  while (!dijq.empty()) {
    _T t = dijq.top();
    dijq.pop();

    int cost = t.first.first;
    int nd = t.second.first;
    int pr = t.second.second;

    if (seen[nd]) continue;
    seen[nd] = true;
    best[nd] = cost;
    parent[nd] = pr;
    for (auto& e: ln[nd]) {
      int d = e.first;
      long long w = e.second;
      dijq.push({{cost + w, w}, {d, nd}});
    }
  }

  long long ans = 0;
  vector<int> v;
  v.reserve(n);
  for (int i = 0; i < n; i++) {
    if (parent[i] == -1) continue;
    int e = getindex(i, parent[i]);
    ans += weight[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N];
bool seen[N];
int parent[N];

void link(int i, int j, long long cost) {
  ln[i].push_back({j, cost});
}

void index(int x, int y, int i) {
  ind[{x, y}] = ind[{y, x}] = i;
}

int getindex(int i, int j) {
  return ind[{i, j}];
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    link(--a, --b, c);
    link(b, a, c);
    index(a, b, i);
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  #define _T pair<pair<long long, long long>, pair<int, int>>
  priority_queue<_T> dijq;
  dijq.push({{0, 0}, {u, -1}});
  while (!dijq.empty()) {
    _T t = dijq.top();
    dijq.pop();

    int cost = -t.first.first;
    int nd = t.second.first;
    int pr = t.second.second;

    if (seen[nd]) continue;
    seen[nd] = true;
    best[nd] = cost;
    parent[nd] = pr;
    for (auto& e: ln[nd]) {
      int d = e.first;
      long long w = e.second;
      dijq.push({{-(cost + w), -w}, {d, nd}});
    }
  }

  long long ans = 0;
  vector<int> v;
  v.reserve(n);
  for (int i = 0; i < n; i++) {
    if (parent[i] == -1) continue;
    int e = getindex(i, parent[i]);
    ans += weight[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 3123123
vector<pair<int, int>> ln[N];
long long SP[N], W;
bool printed[N];
int parent[N], cost[N];

struct Edge { int w, u, v; };

bool operator< (const Edge& a, const Edge& b) { return a.w < b.w; }

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<Edge> E;
  for (int i = 0; i < m; i++) {
    int u, v, w; cin >> u >> v >> w; u--; v--;
    E.push_back({w, u, v});
    ln[u].push_back({v, w});
    ln[v].push_back({u, w});
  }

  int root; cin >> root; root--;
  fill(SP, SP + N, 1ll << 60);
  SP[root] = 0;
  parent[root] = -1;
  set<pair<long long, int>> S;
  S.insert({0ll, root});
  while (!S.empty()) {
    int v = S.begin()->second;
    S.erase(S.begin());
    W += cost[v];
    for (auto e: ln[v]) {
      if (SP[v] + e.second < SP[e.first]) {
        S.erase({e.first, SP[e.first]});
        S.insert({SP[v] + e.second, e.first});
        SP[e.first] = SP[v] + e.second;
        cost[e.first] = e.second;
      }
    }
  }

  auto ECP = E;
  sort(ECP.begin(), ECP.end());
  reverse(ECP.begin(), ECP.end());
  for (int i = 0; i < ECP.size(); i++) {
    Edge e = ECP[i];
    if (SP[e.u] > SP[e.v]) swap(e.u, e.v);
    if (SP[e.v] == SP[e.u] + e.w) { parent[e.v] = e.u; W -= cost[e.v] - e.w; cost[e.v] = e.w; }
  }

  cout << W << endl;
  for (int i = 0; i < m; i++)
    if (parent[E[i].u] == E[i].v || parent[E[i].v] == E[i].u)
      cout << i + 1 << ' ';

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
long long best[N], p[N], w[N];
vector<pair<int, int>> ln[N];
map<pair<int, int>, int> index;

void link(int a, int b, int c) {
  ln[a].push_back({b, c});
}

void dfs(int n) {
  for (auto& e: ln[n]) {
    int v = e.first;
    long long cost = best[n] + (long long)e.second;
    if (cost < best[v]) {
      best[v] = cost;
      p[v] = n;
      dfs(v);
    }
  }
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[i] = c;
    index[{a, b}] = i;
    index[{b, a}] = i;
    link(a, b, c);
    link(b, a, c);
  }

  for (int i = 0; i < n; i++) {
    best[i] = 1e17l;
  }
  int u; cin >> u; u--;
  best[u] = 0l;
  p[u] = -1;
  dfs(u); // Dijkstra?

  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;
    int e = index[{i, p[i]}];
    ans += w[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
long long best[N], p[N], w[N], connector[N];
vector<pair<int, int>> ln[N];
map<pair<int, int>, int> index;

void link(int a, int b, int c) {
  ln[a].push_back({b, c});
}

struct INFO {
  long long cost, connector;
  int dest, parent;
};

bool operator<(const INFO& a, const INFO& b) {
  return a.cost < b.cost ||
    (a.cost == b.cost && a.connector < b.connector);
}

bool operator>(const INFO& a, const INFO& b) {
  return !(operator<(a, b));
}

void dijkstra(int n) {
  priority_queue<INFO, vector<INFO>, greater<INFO>> q;
  q.push({0, 0, n, -1});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cost = t.cost;
    int v = t.dest;
    if (cost < best[v] || (cost == best[v] && connector[v] > t.connector)) {
      best[v] = cost;
      connector[v] = t.connector;
      p[v] = t.parent;
      for (auto e: ln[v]) {
        q.push({best[v] + e.second, e.second, e.first, v});
      }
    }
  }
}

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    w[i] = c;
    index[{a, b}] = i;
    index[{b, a}] = i;
    link(a, b, c);
    link(b, a, c);
  }

  for (int i = 0; i < n; i++) {
    best[i] = 1e17l;
  }
  int u; cin >> u; u--;
  dijkstra(u);

  //~ for (int i = 0; i < n; i++) {
    //~ cout << p[i] << ' ';
  //~ }

  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;
    int e = index[{i, p[i]}];
    ans += w[e];
    v.push_back(e + 1);
  }

  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  #if defined EHSANOO
  freopen("input", "r", stdin);
  #endif

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = 0;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  vector<int> v; v.reserve(n);
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    if (seen[nd]) continue;
    seen[nd] = true;
    if (parent[nd] != -1) {
      v.push_back(ind[{nd, parent[nd]}] + 1);
    }
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] >= e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  //~ for (int i = 0; i < n; i++) {
    //~ cout << parent[i] + 1 << ' ';
  //~ }
  //~ cout << endl;

  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += weight[v[i] - 1];
  }

  cout << ans << endl;
  if (v.size() != n - 1) {
    cout << "ERROR" << endl;
    exit(1);
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long sp[1000000];
int p[1000000];
int n, m;
vector<pair<long long, long long>> links[1000000];
map<pair<long long, long long> , int> mp;

void dfs(int n) {
  //~ cout << "DFS: " << n << endl;
  for (auto& e: links[n]) {
    //~ cout << "TESTING " << e.first << endl;
    int v = e.first;
    long long nc = sp[n] + e.second;
    if (sp[v] > nc) {
      sp[v] = nc;
      p[v] = n;
      dfs(v);
    }
  }
}

long long weight[1000000];
int main() { ios_base::sync_with_stdio(false);
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    links[a - 1].push_back({b - 1, c});
    links[b - 1].push_back({a - 1, c});
    mp[{a - 1, b - 1}] = mp[{b - 1, a - 1}] = i + 1;
    weight[i + 1] = c;
  }

  int u;
  cin >> u;
  u--;

  for (int i = 0; i < n; i++) {
    sp[i] = 999999999999999l;
  }
  sp[u] = 0;
  p[u] = -1;
  dfs(u);

  //~ for (int i = 0; i < n; i++) {
    //~ cout << p[i] << ' ';
  //~ }

  long long ans = 0;
  set<int> ansv;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) continue;

    int e = mp[{i, p[i]}];
    if (ansv.find(e) != ansv.end()) continue;
    ansv.insert(e);
    ans += weight[e];
  }

  cout << ans << endl;
  for (auto e: ansv) cout << e << ' ';

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 3123123
vector<pair<int, int>> ln[N];
long long SP[N], W;
bool printed[N];
int parent[N], cost[N];

struct Edge { int w, u, v; };

bool operator< (const Edge& a, const Edge& b) { return a.w < b.w; }

int main() { ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<Edge> E;
  for (int i = 0; i < m; i++) {
    int u, v, w; cin >> u >> v >> w; u--; v--;
    E.push_back({w, u, v});
    ln[u].push_back({v, w});
    ln[v].push_back({u, w});
  }

  int root; cin >> root; root--;
  fill(SP, SP + N, 1ll << 60);
  SP[root] = 0;
  parent[root] = -1;
  set<pair<long long, int>> S;
  S.insert({0ll, root});
  while (!S.empty()) {
    int v = S.begin()->second;
    S.erase(S.begin());
    W += cost[v];
    for (auto e: ln[v]) {
      if (SP[v] + e.second < SP[e.first]) {
        S.erase({e.first, SP[e.first]});
        S.insert({SP[v] + e.second, e.first});
        SP[e.first] = SP[v] + e.second;
        cost[e.first] = e.second;
      }
    }
  }

  auto ECP = E;
  sort(ECP.begin(), ECP.end());
  reverse(ECP.begin(), ECP.end());
  for (int i = 0; i < ECP.size(); i++) {
    Edge e = ECP[i];
    if (SP[e.u] > SP[e.v]) swap(e.u, e.v);
    if (SP[e.v] == SP[e.u] + e.w) { parent[e.v] = e.u; W -= cost[e.v] - e.w; }
  }

  cout << W << endl;
  for (int i = 0; i < m; i++)
    if (parent[E[i].u] == E[i].v || parent[E[i].v] == E[i].u)
      cout << i + 1 << ' ';

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define INF 1e17l
vector<pair<int, long long>> ln[N];
map<pair<int, int>, int> ind;
long long best[N], weight[N], connector[N];
bool seen[N];
int parent[N];

int main() { ios_base::sync_with_stdio(false);
  #if defined EHSANOO
  freopen("input", "r", stdin);
  #endif

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ln[--a].push_back({--b, c});
    ln[b].push_back({a, c});
    ind[{a, b}] = ind[{b, a}] = i;
    weight[i] = c;
  }

  for (int i = 0; i < n; i++) {
    best[i] = INF;
    connector[i] = INF;
    seen[i] = false;
  }

  int u; cin >> u;
  u--;
  best[u] = 0;
  connector[u] = 0;
  parent[u] = -1;
  priority_queue<pair<long long, int>> q;
  vector<int> v; v.reserve(n);
  q.push({0, u});
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int cc = -t.first;
    int nd = t.second;
    if (seen[nd]) continue;
    seen[nd] = true;
    if (parent[nd] != -1) {
      v.push_back(ind[{nd, parent[nd]}] + 1);
    }
    for (auto& e: ln[nd]) {
      int dest = e.first;
      int nc = cc + e.second;
      if (best[dest] > nc) {
        best[dest] = nc;
        parent[dest] = nd;
        connector[dest] = e.second;
        q.push({-nc, dest});
      } else if (best[dest] == nc && (connector[dest] > e.second)) {
        connector[dest] = e.second;
        parent[dest] = nd;
      }
    }
  }

  //~ for (int i = 0; i < n; i++) {
    //~ cout << parent[i] + 1 << ' ';
  //~ }
  //~ cout << endl;

  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += weight[v[i] - 1];
  }

  cout << ans << endl;
  if (v.size() != n - 1) {
    cout << "ERROR" << endl;
    exit(1);
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }

  return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<int,int>,pair<int,int>> mp;

	vector < vector < pair<int,LL> > > g (n+1);
	vector<LL> d (n+1, INF);
	vrctor <int>  p (n+1);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <int> ed;
    pair <LL,LL> pp;

	for(LL i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min((LL)i,p[i]);
            k = max((LL)i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    for(LL i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 1000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(int i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.push (make_pair (0, s));

	while (!q.empty()) {
		v = q.top().second;  cur_d = q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
            to = g[v][j].first.first;
            len = g[v][j].first.second;

			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(int i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	LL n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[n+1][2]={0};

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,int> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first,len;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.push (make_pair (0, s));
	while (!q.empty()) {
		v = q.top().second;  cur_d = q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			 to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				q.push (make_pair (d[to], to));
			}
			if(d[v] + len <= d[to]){
                a[to][0] = g[v][j].second;
				a[to][1] = len;
			}

		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<int,int>,pair<int,int>> mp;

	vector < vector < pair<int,LL> > > g (n+1);
	vector<LL> d (n+1, INF);
	vector <int>  p (n+1);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <int> ed;
    pair <LL,LL> pp;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min(i,p[i]);
            k = max(i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    for(LL i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

    int a[n+1][2];
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,int> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first,len;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][1] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<int,int>,int> mp;

	vector < vector < pair<LL,LL> > > g (n+1);
	vector<LL> d (n+1, INF),  p (n+1);

	for(int i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = i+1;
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	int ans = 0;
	vector <int> ed(n+1);

	for(int i=1,j,k,pp;i<=n;i++){
        if(i!=s && d[i]<INF){
            ans++;
            j = min((LL)i,p[i]);
            k = max((LL)i,p[i]);
            pp = mp[make_pair(j,k)];
            ed.push_back(pp);
        }
	}
    cout << ans << endl;

    for(int i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<int,int>,pair<int,int>> mp;

	vector < vector < pair<LL,LL> > > g (n+1);
	vector<LL> d (n+1, INF),  p (n+1);

	for(int i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <int> ed;
    pair <int,int> pp;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min((LL)i,p[i]);
            k = max((LL)i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    for(int i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<LL,LL>,pair<LL,LL>> mp;

	vector < vector < pair<LL,LL> > > g (n+1);
	vector<LL> d (n+1, INF),  p (n+1);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <LL> ed;
    pair <LL,LL> pp;

	for(LL i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min((LL)i,p[i]);
            k = max((LL)i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    for(LL i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

    int a[n+1][2];
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1);
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,int> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first,len;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][1] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<int,int>,pair<int,int>> mp;

	vector < vector < pair<LL,LL> > > g (n+1);
	vector<LL> d (n+1, INF),  p (n+1);

	for(int i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <int> ed;
    pair <int,int> pp;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min((LL)i,p[i]);
            k = max((LL)i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    sort(ed.begin(),ed.end());

    for(int i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	LL n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,int> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first,len;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<int,int>,pair<int,int>> mp;

	vector < vector < pair<int,LL> > > g (n+1);
	vector<LL> d (n+1, INF),  p (n+1);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <LL> ed;
    pair <LL,LL> pp;

	for(LL i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min((LL)i,p[i]);
            k = max((LL)i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    for(LL i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.push (make_pair (0, s));
	while (!q.empty()) {
		v = q.top().second;  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			 to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 1000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(int i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.push (make_pair (0, s));

	while (!q.empty()) {
		v = q.top().second;  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			 to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(int i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

	map <pair<LL,LL>,pair<LL,LL>> mp;

	vector < vector < pair<LL,LL> > > g (n+1);
	vector<LL> d (n+1, INF),  p (n+1);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <LL> ed;
    pair <LL,LL> pp;

	for(LL i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min((LL)i,p[i]);
            k = max((LL)i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    sort(ed.begin(),ed.end());

    for(LL i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	LL n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q(n+1);

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first,len;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.push (make_pair (0, s));
	while (!q.empty()) {
		v = q.top().second;  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			 to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				q.push (make_pair (-d[to], to));
			}
			if(d[v] + len <= d[to]){
                a[to][0] = g[v][j].second;
				a[to][1] = len;
			}

		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	LL n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first,len;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    set < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.insert (make_pair (0, s));
	while (!q.empty()) {
		v = (*q.begin()).second;  cur_d = -(*q.begin()).first;
		q.erase(q.begin());
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			 to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				q.insert (make_pair (-d[to], to));
			}
			if(d[v] + len <= d[to]){
                a[to][0] = g[v][j].second;
				a[to][1] = len;
			}

		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 10000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    set < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.insert (make_pair (0, s));
	while (!q.empty()) {
		v = (*q.begin()).second;  cur_d = (*q.begin()).first;
		q.erase(q.begin());
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			 to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len < d[to]) {
				d[to] = d[v] + len;
				q.insert (make_pair (d[to], to));
			}
			if(d[v] + len <= d[to]){
                a[to][0] = g[v][j].second;
				a[to][1] = len;
			}

		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

const LL INF = 10000000000000000;
map <pair<int,int>,pair<int,int>> mp;
vector < vector < pair<int,LL> > > g (300001);
vector<LL> d (300001, INF);
vector <int>  p (300001);

int main () {
    std::ios_base::sync_with_stdio(false);
	LL n,u,m,s;
	cin >> n >> m;

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(v2,c));
        g[v2].push_back(make_pair(v1,c));
        mp[make_pair(min(v1,v2),max(v1,v2))] = make_pair(i+1,c);
	}

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,LL> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			LL to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				p[to] = v;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;
	vector <int> ed;
    pair <LL,LL> pp;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF){
            j = min(i,p[i]);
            k = max(i,p[i]);
            pp = mp[make_pair(j,k)];
            ans += pp.second;
         //   cout << " j,k " << j << " " << k << endl;
          //  cout << " cost =  " << pp.second << endl;
            ed.push_back(pp.first);
        }
	}
    cout << ans << endl;

    for(LL i=0;i<ed.size();i++)
        cout << ed[i] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

    const LL INF = 1000000000000000;
	int n=300000,u,m,s;
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);
    int a[300001][2]={0};
    priority_queue < pair<LL,int> > q;

int main () {
    std::ios_base::sync_with_stdio(false);

	cin >> n >> m;

	for(int i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

    int v,to; LL cur_d,len;
	q.push (make_pair (0, s));

	while (!q.empty()) {
		v = q.top().second;  cur_d = q.top().first;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
            to = g[v][j].first.first;
            len = g[v][j].first.second;

			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(int i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long int
#define mod 1000000007

using namespace std;

int main () {
    std::ios_base::sync_with_stdio(false);

    const LL INF = 10000000000000000;

	LL n,u,m,s;
	cin >> n >> m;

    int a[n+1][2];
	vector < vector < pair< pair<int,int>,int> > > g (n+1);
	vector<LL> d (n+1, INF);

	for(LL i=0,v1,v2,c;i<m;i++){
        cin >> v1 >> v2 >> c;
        g[v1].push_back(make_pair(make_pair(v2,c),i+1));
        g[v2].push_back(make_pair(make_pair(v1,c),i+1));
    }

	cin >> s;

	d[s] = 0;

	priority_queue < pair<LL,int> > q;

	q.push (make_pair (0, s));
	while (!q.empty()) {
		LL v = q.top().second,  cur_d = -q.top().first,len;
		q.pop();
		if (cur_d > d[v])  continue;

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first.first;
				 len = g[v][j].first.second;
			if (d[v] + len <= d[to]) {
				d[to] = d[v] + len;
				a[to][0] = g[v][j].second;
				a[to][1] = len;
				q.push (make_pair (-d[to], to));
			}
		}
	}

	LL ans = 0;

	for(int i=1,j,k;i<=n;i++){
        if(i!=s && d[i]<INF)
            ans += a[i][1];

	}
    cout << ans << endl;

    for(LL i=1;i<=n;i++)
       if(a[i][1])
        cout << a[i][0] << " ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n, m;
vector<vector<pair<pair<ll, ll> , int>   > > G;
bool vis[300009];
vector<int> ans;
vector<ll> temp;
void d(int u)
{

    priority_queue < pair<pair<ll, ll>  , int> , vector< pair<pair<ll, ll>  , int> > , greater< pair<pair<ll, ll>  , int> > > Q;
    Q.push(make_pair(make_pair(0 , u) , -1));
    while (!Q.empty())
    {
        pair<pair<ll, ll>  , int> now = Q.top(); Q.pop();
        ll nod = now.first.second;
        if (vis[nod]) continue;
        vis[nod] = 1;
        ll e = now.second;
        if(e != -1)
            ans.push_back(e);
        ll cost = now.first.first;

        for (int j=0;j<G[nod].size();j++)
        {
            ll v = G[nod][j].first.first;
            ll c = G[nod][j].first.second;
            ll ed = G[nod][j].second;
            if (!vis[v])
            {
                Q.push(make_pair(make_pair(cost + c , v) , ed));
            }
        }
    }
}
int main()
{
    scanf("%I64d %I64d", &n, &m);
    G.resize(n+2);
    for (int i=0;i<m;i++)
    {
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        G[a].push_back(make_pair(make_pair(b, c) , i+1));
        G[b].push_back(make_pair(make_pair(a, c) , i+1));
        temp.push_back(c);
    }
    int u; scanf("%d", &u);
    d(u);
    ll sum = 0;
    for (int i=0;i<ans.size();i++)
    {
        sum += temp[ans[i]-1];
    }
    cout << sum << endl;
    for (int i=0;i<ans.size();i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <time.h>
#include <bitset>
#include <sstream>
#define Set(name,value) memset(name,value,sizeof(name))
#define INF 100000000000000000
#define UNVISITED false
#define VISITED true
#define intr int register
#define rep(i,n) for (intr i=0;i<n;i++)
#define iOS ios_base::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pi;
typedef pair <ll, ll> ii;
typedef vector <int> vi;
const int OO = (int)1e6;
ll n, m, u;
//set<int> s; //!store the indexes
//map<pi, ll> M; //! map the edge to its index
//
////map<pi, bool> MM;
////map<pi, ll> mms;
//map<ll, ll> mm;
//ll total_wight;
//ll d[400000];
struct edge
{
    int from, to;
    ll w;
    edge(int f, int t, ll W)
    {
        from = f, to = t, w = W;
    }
};
vector<edge> MyEdges;
vector<vector<pi> > G;
vector<ll> dist;
vector<int> parent;
vector<int> in;
ll Dijextra(int start)
{
    priority_queue <pi, vector<pi>, greater<pi> > Q;
    Q.push(make_pair(0, start));
    dist[start] = 0;
    in[start] = 0;
    while (!Q.empty())
    {
        pi top = Q.top(); Q.pop();
        ll cost = top.first;
        ll from = top.second;
        rep(i, G[from].size())
        {
            ll to = G[from][i].first;
            ll wight = G[from][i].second + cost;
            if (wight < dist[to])
            {
                dist[to] = wight;
                in[to] = wight - cost;
                parent[to] = from;
                Q.push(make_pair(wight, to));
            }
            else if (wight == dist[to])
            {
                if ((wight - cost) < in[to])
                {
                    in[to] = wight-cost;
                    parent[to] = from;
                }
            }
        }
    }
    ll res = 0;
    for (int i=1;i<=n;++i)
        res += in[i];
        return res;
}
int main()
//{
 {

     iOS;
//    freopen("in.txt","r",stdin);
    cin>>n>>m;
    ll c = 1;
    G = vector<vector<pi> > (n+5);
//    set<pair<ll, pair<ll, ll> > > V;
    dist = vector<ll> (n+5, INF);
    parent = vector<int> (n+5);
    in = vector<int> (n+2, INF);
    for (int i=1;i<=n;++i)
        parent[i] = i;
    rep(i, m)
    {
        int x, y, z;
        cin>>x>>y>>z;
//        M[make_pair(x, y)] = c;
//        M[make_pair(y, x)] = c;
//        mm[c] = z;
        G[x].push_back(make_pair(y, z));
        G[y].push_back(make_pair(x, z));
        MyEdges.push_back(edge(x, y, z));
//        mm[make_pair(x, y)] = z;
//        mm[make_pair(y, x)] = z;
//        V.insert(make_pair(z, make_pair(x, y)));

    }

    cin>>u;
    ll res = Dijextra(u);
    cout<<res<<endl;
    rep(i, m)
    {
        int x = MyEdges[i].from;
        int y = MyEdges[i].to;
        if (parent[x] == y || parent[y] == x) cout<<i+1<<" ";
    }
    cout<<endl;
//    cout<<total_wight<<endl;
//    set<int>::iterator itr1 = s.begin();
//    while (itr1 != s.end())
//    {
//        total_wight += mm[(*itr1)];
//        itr1++;
//    }
//    itr1 = s.begin();
//    cout<<total_wight<<endl;
//    while (itr1 != s.end())
//    {
//        cout<<(*itr1)<<" ";
//        itr1++;
//    }
//    cout<<endl;
//    bool vis[n+3];
//    Set(vis, false);
//    set<pair<ll, pair<ll, ll> > >::iterator itr = V.begin();
//    while (itr != V.end())
//    {
//        pair<ll, ll> P = (*itr).second;
//        if (abs(d[(*itr).second.first] - d[(*itr).second.second]) != (*itr).first)
//               mm[P] = 0;
//
//        itr++;
//    }
//    itr = V.begin();
//    while (itr != V.end())
//    {
//        pair<ll, ll> P = (*itr).second;
//        int x = (*itr).second.first, y = (*itr).second.second;
//        if ((!vis[x] || !vis[y]) && (mm[P]))
//        {
//            vis[x] = true;
//            vis[y] = true;
//            sum += (*itr).first;
//        }
//        itr++;
//    }
//    bool yes[m+5];
//    Set(yes, true);
//    map<pi, ll>::iterator itr = mms.begin();
//    while (itr != mms.end())
//    {
//        if (abs(d[(*itr).first.first] - d[(*itr).first.second]) != (*itr).second)
//        {
//            yes[M[(*itr).first]] = false;
//        }
//        itr++;
//    }
//    for (int i=1;i<=m;++i)
//        if (yes[i])
//
//        {
////            cout<<"SHIT"<<endl;
//        sum += mm[i];
//        }
//
//    cout<<sum<<endl;

//    while (itr != s.end())
//    {
//        sum += mm[(*itr)];
//        itr++;
//    }
//    itr = s.begin();
//    cout<<sum<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n, m;
vector<vector<pair<pair<ll, ll>, ll>   > > G;
bool vis[300009];
vector<ll> ans;
vector<ll> temp;
struct edge
{
    ll nod, c, e;
    edge() {}
    edge (ll _nod, ll _c, ll _e)
    {
        nod = _nod;
        c = _c;
        e = _e;
    }

    bool operator < ( const edge& a) const
    {
        if( c==a.c ) return e < a.e ;
        return c > a.c ;
    }
};
void d(ll u)
{

    priority_queue < edge > Q;
    Q.push(edge(u, 0, -1));
    while (!Q.empty())
    {
        edge now = Q.top();
        Q.pop();
        ll nod = now.nod;
        if (vis[nod]) continue;
        vis[nod] = 1;
        ll e = now.e;
        if(e != -1)
            ans.push_back(e);
        ll cost = now.c;

        for (int j=0; j<G[nod].size(); j++)
        {
            ll v = G[nod][j].first.first;
            ll c = G[nod][j].first.second;
            ll ed = G[nod][j].second;
            if (!vis[v])
            {
                Q.push(edge(v, c + cost, ed));
            }
        }
    }
}
int main()
{
    scanf("%I64d %I64d", &n, &m);
    G.resize(n+2);
    for (int i=0; i<m; i++)
    {
        ll a, b, c;
        scanf("%I64d %I64d %I64d", &a, &b, &c);
        G[a].push_back(make_pair(make_pair(b, c), i+1));
        G[b].push_back(make_pair(make_pair(a, c), i+1));
        temp.push_back(c);
    }
    ll u;
    scanf("%I64d", &u);
    d(u);
    ll sum = 0;
    for (int i=0; i<ans.size(); i++)
    {
        sum += temp[ans[i]-1];
    }
    cout << sum << endl;
    for (int i=0; i<ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n, m;
vector<vector<pair<pair<ll, ll> , ll>   > > G;
bool vis[300009];
vector<ll> ans;
vector<ll> temp;
void d(ll u)
{

    priority_queue < pair<pair<ll, ll>  , ll> , vector< pair<pair<ll, ll>  , ll> > , greater< pair<pair<ll, ll>  , ll> > > Q;
    Q.push(make_pair(make_pair(0 , -1) , u));
    while (!Q.empty())
    {
        pair<pair<ll, ll>  , ll> now = Q.top(); Q.pop();
        ll nod = now.second;
        if (vis[nod]) continue;
        vis[nod] = 1;
        ll e = now.first.second;
        if(e != -1)
            ans.push_back(e);
        ll cost = now.first.first;

        for (int j=0;j<G[nod].size();j++)
        {
            ll v = G[nod][j].first.first;
            ll c = G[nod][j].first.second;
            ll ed = G[nod][j].second;
            if (!vis[v])
            {
                Q.push(make_pair(make_pair(cost + c , ed) , v));
            }
        }
    }
}
int main()
{
    scanf("%I64d %I64d", &n, &m);
    G.resize(n+2);
    for (int i=0;i<m;i++)
    {
        ll a, b, c; scanf("%I64d %I64d %I64d", &a, &b, &c);
        G[a].push_back(make_pair(make_pair(b, c) , i+1));
        G[b].push_back(make_pair(make_pair(a, c) , i+1));
        temp.push_back(c);
    }
    ll u; scanf("%I64d", &u);
    d(u);
    ll sum = 0;
    for (int i=0;i<ans.size();i++)
    {
        sum += temp[ans[i]-1];
    }
    cout << sum << endl;
    for (int i=0;i<ans.size();i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n, m;
vector<vector<pair<pair<ll, ll>, ll>   > > G;
bool vis[300009];
vector<ll> ans;
vector<ll> temp;
struct edge
{
    ll nod, c, e;
    edge() {}
    edge (ll _nod, ll _c, ll _e)
    {
        nod = _nod;
        c = _c;
        e = _e;
    }

    bool operator < ( const edge& a) const
    {
        if( c==a.c ) return e > a.e ;
        return c > a.c ;
    }
};
void d(ll u)
{

    priority_queue < edge > Q;
    Q.push(edge(u, 0, -1));
    while (!Q.empty())
    {
        edge now = Q.top();
        Q.pop();
        ll nod = now.nod;
        if (vis[nod]) continue;
        vis[nod] = 1;
        ll e = now.e;
        if(e != -1)
            ans.push_back(e);
        ll cost = now.c;

        for (int j=0; j<G[nod].size(); j++)
        {
            ll v = G[nod][j].first.first;
            ll c = G[nod][j].first.second;
            ll ed = G[nod][j].second;
            if (!vis[v])
            {
                Q.push(edge(v, c + cost, ed));
            }
        }
    }
}
int main()
{
    scanf("%I64d %I64d", &n, &m);
    G.resize(n+2);
    for (int i=0; i<m; i++)
    {
        ll a, b, c;
        scanf("%I64d %I64d %I64d", &a, &b, &c);
        G[a].push_back(make_pair(make_pair(b, c), i+1));
        G[b].push_back(make_pair(make_pair(a, c), i+1));
        temp.push_back(c);
    }
    ll u;
    scanf("%I64d", &u);
    d(u);
    ll sum = 0;
    for (int i=0; i<ans.size(); i++)
    {
        sum += temp[ans[i]-1];
    }
    cout << sum << endl;
    for (int i=0; i<ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <time.h>
#include <bitset>
#include <sstream>
#define Set(name,value) memset(name,value,sizeof(name))
#define INF 1000000000
#define UNVISITED false
#define VISITED true
#define intr int register
#define rep(i,n) for (intr i=0;i<n;i++)
#define iOS ios_base::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pi;
typedef pair <ll, ll> ii;
typedef vector <int> vi;
const int OO = (int)1e6;
ll n, m, u;
vector<vector<pi> > G;
set<int> s; //!store the indexes
map<pi, ll> M; //! map the edge to its index

//map<pi, bool> MM;
//map<pi, ll> mms;
map<ll, ll> mm;
ll total_wight;
ll d[400000];
void Dijextra(int start)
{
    bool visited[G.size()+1];
    Set(visited, UNVISITED);
    priority_queue <pair<pi, pi> , vector<pair<pi, pi> >, greater<
    pair<pi, pi> > > Q;
    Q.push(make_pair(make_pair(0, 0), make_pair(0, start)));
    int w;
    while (!Q.empty())
    {
        pair<pi, pi> top = Q.top(); Q.pop();
        w = top.first.first;int  node = top.second.second;
        int parent = top.second.first;
        if (visited[node]) continue;
        visited[node] = true;
        pi p = top.second;
//        total_wight += top.first.second;
        d[node] = w;
        if (top.second.first && (abs(d[node] - d[parent] == top.first.second)))
            s.insert(M[p]); //! take this edge
        for (int i=0;i<G[node].size();++i)
        {
            int child = G[node][i].first;
            int weight = w + G[node][i].second;
            if (!visited[child])
            Q.push(make_pair(make_pair(weight, G[node][i].second), make_pair(node, G[node][i].first)));
        }
    }
}
int main()
{
    iOS;
//    freopen("in.txt","r",stdin);
    cin>>n>>m;
    ll c = 1;
    G = vector<vector<pi> > (n+5);
    set<pair<ll, pair<ll, ll> > > V;
    rep(i, m)
    {
        int x, y, z;
        cin>>x>>y>>z;
        M[make_pair(x, y)] = c;
        M[make_pair(y, x)] = c;
        mm[c] = z;
        G[x].push_back(make_pair(y, z));
        G[y].push_back(make_pair(x, z));
        c++;
//        mm[make_pair(x, y)] = z;
//        mm[make_pair(y, x)] = z;
//        V.insert(make_pair(z, make_pair(x, y)));

    }

    cin>>u;
    Dijextra(u);
//    cout<<total_wight<<endl;
    set<int>::iterator itr1 = s.begin();
    while (itr1 != s.end())
    {
        total_wight += mm[(*itr1)];
        itr1++;
    }
    itr1 = s.begin();
    cout<<total_wight<<endl;
    while (itr1 != s.end())
    {
        cout<<(*itr1)<<" ";
        itr1++;
    }
    cout<<endl;
//    bool vis[n+3];
//    Set(vis, false);
//    set<pair<ll, pair<ll, ll> > >::iterator itr = V.begin();
//    while (itr != V.end())
//    {
//        pair<ll, ll> P = (*itr).second;
//        if (abs(d[(*itr).second.first] - d[(*itr).second.second]) != (*itr).first)
//               mm[P] = 0;
//
//        itr++;
//    }
//    itr = V.begin();
//    while (itr != V.end())
//    {
//        pair<ll, ll> P = (*itr).second;
//        int x = (*itr).second.first, y = (*itr).second.second;
//        if ((!vis[x] || !vis[y]) && (mm[P]))
//        {
//            vis[x] = true;
//            vis[y] = true;
//            sum += (*itr).first;
//        }
//        itr++;
//    }
//    bool yes[m+5];
//    Set(yes, true);
//    map<pi, ll>::iterator itr = mms.begin();
//    while (itr != mms.end())
//    {
//        if (abs(d[(*itr).first.first] - d[(*itr).first.second]) != (*itr).second)
//        {
//            yes[M[(*itr).first]] = false;
//        }
//        itr++;
//    }
//    for (int i=1;i<=m;++i)
//        if (yes[i])
//
//        {
////            cout<<"SHIT"<<endl;
//        sum += mm[i];
//        }
//
//    cout<<sum<<endl;

//    while (itr != s.end())
//    {
//        sum += mm[(*itr)];
//        itr++;
//    }
//    itr = s.begin();
//    cout<<sum<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n, m;
vector<vector<pair<pair<ll, ll>, ll>   > > G;
bool vis[300009];
vector<ll> ans;
vector<ll> temp;
struct edge
{
    ll nod, c, e, ed;
    edge() {}
    edge (ll _nod, ll _c, ll _e, ll _ed)
    {
        nod = _nod;
        c = _c;
        e = _e;
        ed = _ed;
    }

    bool operator < ( const edge& a) const
    {
        if( c == a.c ) return ed > a.ed ;
        return c > a.c ;
    }
};
void d(ll u)
{

    priority_queue < edge > Q;
    Q.push(edge(u, 0, 0, -1));
    while (!Q.empty())
    {
        edge now = Q.top();
        Q.pop();
        ll nod = now.nod;
        if (vis[nod]) continue;
        vis[nod] = 1;
        ll e = now.ed;
        if(e != -1)
            ans.push_back(now.e);
        ll cost = now.c;

        for (int j=0; j<G[nod].size(); j++)
        {
            ll v = G[nod][j].first.first;
            ll c = G[nod][j].first.second;
            ll ed = G[nod][j].second;
            if (!vis[v])
            {
                Q.push(edge(v, c + cost, c , ed));
            }
        }
    }
}
int main()
{
    scanf("%I64d %I64d", &n, &m);
    G.resize(n+2);
    for (int i=0; i<m; i++)
    {
        ll a, b, c;
        scanf("%I64d %I64d %I64d", &a, &b, &c);
        G[a].push_back(make_pair(make_pair(b, c), i+1));
        G[b].push_back(make_pair(make_pair(a, c), i+1));
        temp.push_back(c);
    }
    ll u;
    scanf("%I64d", &u);
    d(u);
    ll sum = 0;
    for (int i=0; i<ans.size(); i++)
    {
        sum += temp[ans[i]-1];
    }
    cout << sum << endl;
    for (int i=0; i<ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n, m;
vector<vector<pair<pair<ll, ll>, ll>   > > G;
bool vis[300009];
vector<ll> ans;
vector<ll> temp;
struct edge
{
    ll nod, c, e, ed;
    edge() {}
    edge (ll _nod, ll _c, ll _e, ll _ed)
    {
        nod = _nod;
        c = _c;
        e = _e;
        ed = _ed;
    }

    bool operator < ( const edge& a) const
    {
        if( c == a.c ) return ed > a.ed ;
        return c > a.c ;
    }
};
void d(ll u)
{

    priority_queue < edge > Q;
    Q.push(edge(u, 0, -1, 0));
    while (!Q.empty())
    {
        edge now = Q.top();
        Q.pop();
        ll nod = now.nod;
        if (vis[nod]) continue;
        vis[nod] = 1;
        ll e = now.e;
        if(e != -1)
            ans.push_back(now.e);
        ll cost = now.c;

        for (int j=0; j<G[nod].size(); j++)
        {
            ll v = G[nod][j].first.first;
            ll c = G[nod][j].first.second;
            ll ed = G[nod][j].second;
            if (!vis[v])
            {
                Q.push(edge(v, c + cost, ed , c));
            }
        }
    }
}
int main()
{
    scanf("%I64d %I64d", &n, &m);
    G.resize(n+2);
    for (int i=0; i<m; i++)
    {
        ll a, b, c;
        scanf("%I64d %I64d %I64d", &a, &b, &c);
        G[a].push_back(make_pair(make_pair(b, c), i+1));
        G[b].push_back(make_pair(make_pair(a, c), i+1));
        temp.push_back(c);
    }
    ll u;
    scanf("%I64d", &u);
    d(u);
    ll sum = 0;
    for (int i=0; i<ans.size(); i++)
    {
        sum += temp[ans[i]-1];
    }
    cout << sum << endl;
    for (int i=0; i<ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}


import java.util.Scanner;

public class DZY_Loves_Hash {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner in=new Scanner (System.in);
        int p=in.nextInt();
        int n=in.nextInt();
        int arr[]=new int[n];
        boolean check[]=new boolean[p];
        int z=0;
        boolean t=false;
        for(int i=0;i<n;i++){
        	int k=in.nextInt();
        	z=(k%p);
        //	System.out.println(z);

        	if(check[z]==true)
        	{
        		System.out.println(i+1);
        		t=true;
        		return;

        	}

        	check[z]=true;

}
        if(t==false)
        	System.out.println(-1);
}

}


import java.util.Scanner;

public class DZY_Loves_Hash {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner in=new Scanner (System.in);
        int p=in.nextInt();
        int n=in.nextInt();
        int arr[]=new int[n];
        boolean check[]=new boolean[n];
        int z=0;
        boolean t=false;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
      	    check[i]=false;
        }
        for(int i=0;i<n;i++){
        	z=(arr[i]%p);
        //	System.out.println(z);
        	if(z>n){
        		z=n-1;
        	}
        	if(check[z]==true)
        	{
        		System.out.println(i+1);
        		t=true;
        		return;

        	}

        	check[z]=true;

}
        if(t==false)
        	System.out.println(-1);
}

}


import java.util.Scanner;

public class DZY_Loves_Hash {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner in=new Scanner (System.in);
        int p=in.nextInt();
        int n=in.nextInt();
        long arr[]=new long[n];
        boolean check[]=new boolean[n];
        int z=0;
        boolean t=false;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextLong();
      	    check[i]=false;
        }
        for(int i=0;i<n;i++){
        	z=(int) (arr[i]%p);
        	if(z>n){
        		System.out.println(i+1);
        		t=true;
        		return;
        	}
        	if(check[z]==true)
        	{
        		System.out.println(i+1);
        		t=true;
        		return;

        	}

        	check[z]=true;

}
        if(t==false)
        	System.out.println(-1);
}

}


/*
 * Code Author: Akshay Miterani
 * DA-IICT
 */
import java.io.*;
import java.util.*;

public class MainB {

	public static void main(String args[]){
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		//----------My Code Starts Here----------
		int p=in.nextInt();
		int n=in.nextInt();
		int a[]=new int[n];
		int h[]=new int[p];
		for(int i=0;i<n;i++){
			a[i]=in.nextInt();
			int hash=a[i]%p;
			if(h[hash]!=0){
				System.out.println(i+1);
				return;
			}
			h[hash]=a[i];
		}
		System.out.println("-1");
		out.close();
		//---------------The End------------------
	}

	static class InputReader {
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;

	    public InputReader(InputStream inputstream) {
	      reader = new BufferedReader(new InputStreamReader(inputstream));
	      tokenizer = null;
	    }

	    public String nextLine(){
	    	String fullLine=null;
	    	while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	              fullLine=reader.readLine();
	            } catch (IOException e) {
	              throw new RuntimeException(e);
	            }
	            return fullLine;
	          }
	          return fullLine;
	    }
		public String next() {
	      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	        try {
	          tokenizer = new StringTokenizer(reader.readLine());
	        } catch (IOException e) {
	          throw new RuntimeException(e);
	        }
	      }
	      return tokenizer.nextToken();
	    }
		public long nextLong() {
		      return Long.parseLong(next());
		    }
	    public int nextInt() {
	      return Integer.parseInt(next());
	    }
	  }
}


/*
 * Code Author: Akshay Miterani
 * DA-IICT
 */
import java.io.*;
import java.util.*;

public class MainB {

	public static void main(String args[]){
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		//----------My Code Starts Here----------
		int p=in.nextInt();
		int n=in.nextInt();
		int a[]=new int[n];
		int h[]=new int[p];
		for(int i=0;i<n;i++){
			a[i]=in.nextInt();
			int hash=a[i]%p;
			if(h[hash]!=0){
				System.out.println(i+1);
				return;
			}
			h[hash]=1;
		}
		System.out.println("-1");
		out.close();
		//---------------The End------------------
	}

	static class InputReader {
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;

	    public InputReader(InputStream inputstream) {
	      reader = new BufferedReader(new InputStreamReader(inputstream));
	      tokenizer = null;
	    }

	    public String nextLine(){
	    	String fullLine=null;
	    	while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	              fullLine=reader.readLine();
	            } catch (IOException e) {
	              throw new RuntimeException(e);
	            }
	            return fullLine;
	          }
	          return fullLine;
	    }
		public String next() {
	      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	        try {
	          tokenizer = new StringTokenizer(reader.readLine());
	        } catch (IOException e) {
	          throw new RuntimeException(e);
	        }
	      }
	      return tokenizer.nextToken();
	    }
		public long nextLong() {
		      return Long.parseLong(next());
		    }
	    public int nextInt() {
	      return Integer.parseInt(next());
	    }
	  }
}


import java.util.Scanner;

public class DZYLovesHash {

	private static Scanner input;

	public static void main(String[] args) {

		input = new Scanner(System.in);

		int p, n, collision = 0;
		boolean found = false;

		p = input.nextInt();
		n = input.nextInt();

		int[] numbers = new int[n];

		for (int i = 1; i < n + 1; i++) {
			int currentNumber = input.nextInt();
			int position = currentNumber % p;
			if (numbers[position] == 1 && !found) {
				collision = i;
				found = true;
			} else {
				numbers[position]++;
			}
		}

		if (found) {
			System.out.println(collision);
		} else {
			System.out.println(-1);
		}

	}

}


import java.util.Scanner;

public class DZYLovesHash {

	private static Scanner input;

	public static void main(String[] args) {

		input = new Scanner(System.in);

		int p, n, collision = 0;
		boolean found = false;

		p = input.nextInt();
		n = input.nextInt();

		int[] numbers = new int[p];

		for (int i = 1; i < n + 1; i++) {
			int currentNumber = input.nextInt();
			int position = currentNumber % p;
			if (numbers[position] == 1 && !found) {
				collision = i;
				found = true;
			} else {
				numbers[position]++;
			}
		}

		if (found) {
			System.out.println(collision);
		} else {
			System.out.println(-1);
		}

	}

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author Nurlybek
 */
public class HashCode {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int k = in.nextInt();
        int n = in.nextInt();

        int cell[] = new int[301];
        int ans = -1;

        for(int i = 1; i < n; i++) {

            int x = in.nextInt();
            x %= k;

            if(cell[x] == 0) {
                cell[x] = 1;
                continue;
            }
            else {
                if(ans == -1) {
                    ans = i;
                }
            }
        }
        if(ans != -1) {
            System.out.println(ans);
        }
        else {
            System.out.println(-1);
        }
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author Nurlybek
 */
public class HashCode {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int k = in.nextInt();
        int n = in.nextInt();

        int cell[] = new int[301];
        int ans = -1;

        for(int i = 0; i < n; i++) {

            int x = in.nextInt();
            x %= k;

            if(cell[x] == 0) {
                cell[x] = 1;
                continue;
            }
            else {
                if(ans == -1) {
                    ans = i;
                }
            }
        }
        if(ans != -1) {
            System.out.println(ans+1);
        }
        else {
            System.out.println("-1");
        }
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author Nurlybek
 */
public class HashCode {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int k = in.nextInt();
        int n = in.nextInt();

        int cell[] = new int[301];
        int ans = -1;

        for(int i = 1; i < n; i++) {

            int x = in.nextInt();
            x %= k;

            if(cell[x] == 0) {
                cell[x] = 1;
                continue;
            }
            else {
                if(ans == -1) {
                    ans = i;
                }
            }
        }
        if(ans != -1) {
            System.out.println(ans);
        }
        else {
            System.out.println(ans);
        }
    }
}