func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 100100;   const long long INF = 1000 * 1000 * 1000LL * 1000 * 1000;   vector<pair<int, int> > adj1[N];   vector<pair<long long, pair<int, int> > > e;   set<pair<long long, int> > s;   long long d[N];   int p[N], par[N], sz[N], flag(1);   void Dijkstra() {     while (s.size()) {       auto u = *s.begin();       s.erase(u);       for (auto v : adj1[u.second]) {         long long w = u.first + v.second;         if (w < d[v.first]) {           s.erase({d[v.first], v.first});           d[v.first] = w;           p[v.first] = p[u.second];           s.insert({d[v.first], v.first});         }       }     }     return;   }   int findpar(int v) {     if (v == par[v]) return v;     return (par[v] = findpar(par[v]));   }   bool merge(int u, int v) {     u = findpar(u), v = findpar(v);     if (u == v) return 0;     if (sz[u] < sz[v]) swap(u, v);     sz[u] += sz[v];     par[v] = u;     return 1;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m, k, u, v, w;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       adj1[--u].push_back({--v, w});       adj1[v].push_back({u, w});     }     fill(d, d + n, INF);     cin >> k;     for (int i = 0; i < k; i++) {       cin >> u;       d[--u] = 0;       if (!u) flag = 0;     }     for (int i = 0; i < n; i++) {       p[i] = i;       par[i] = i, sz[i] = 1;       s.insert({d[i], i});     }     Dijkstra();     for (int i = 0; i < n; i++)       for (auto u : adj1[i])         if (p[i] < p[u.first]) {           long long w = d[i] + d[u.first] + u.second;           e.push_back({w, {p[i], p[u.first]}});         }     int cmp = k;     long long ans(0), ans2(0);     sort(e.begin(), e.end());     for (int i = 0; i < e.size() && cmp > 1; i++) {       if (merge(e[i].second.first, e[i].second.second)) {         cmp--;         ans += e[i].first;       }     }     if (flag) ans += d[0];     cout << ((cmp == 1) ? ans : -1) << endl;     return 0;   }   