#include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; struct UnionFind { vector par; vector rank; UnionFind(int n) { par.resize(n); rep(i, n) par[i] = i; rank.resize(n, 0); } int find(int i) { if (i == par[i]) return par[i]; else return par[i] = find(par[i]); } void unite(int i, int j) { i = find(i), j = find(j); if (i == j) return; if (rank[i] < rank[j]) { par[i] = j; } else { par[j] = i; if (rank[i] == rank[j]) rank[i]++; } } }; int main() { int n, m, k; cin >> n >> m >> k; struct Edge { int a, b, c; }; vector edges; rep(_, m) { int a, b, c; cin >> a >> b >> c; edges.push_back(Edge{a - 1, b - 1, c}); } long long sum = 0; UnionFind uf(n); vector special(m, false); rep(_, k) { int i; cin >> i; uf.unite(edges[i - 1].a, edges[i - 1].b); sum += (long long)edges[i - 1].c; special[i] = true; } struct E { int to, c; bool operator<(const E &r) const { return c > r.c; } }; vector> g(n); rep(i, m) { auto a = uf.find(edges[i].a), b = uf.find(edges[i].b); if (a != b) { g[a].push_back(E{b, edges[i].c}); g[b].push_back(E{a, edges[i].c}); } } auto prim = [&](vector> &g) { vector visited(n, false); priority_queue q; auto s = uf.find(0); visited[s] = true; for (auto e : g[s]) { q.push(e); } long long ret = 0; while (q.size() > 0) { auto e = q.top(); q.pop(); if (visited[e.to]) continue; visited[e.to] = true; ret += (long long)e.c; for (auto ne : g[e.to]) { if (!visited[ne.to]) { q.push(ne); } } } return ret; }; sum += prim(g); auto tot = accumulate( edges.begin(), edges.end(), 0LL, [&](long long res, const auto &e) { return res + (long long)e.c; }); cout << tot - sum << endl; return 0; }