#include using namespace std; struct union_find { int n; vector t; union_find(int n) : n(n) { t.assign(n, -1); } int size(int x) { return -t[root(x)]; } int root(int x) { if (t[x] < 0) { return x; } return t[x] = root(t[x]); } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { if (same(x, y)) { return false; } x = root(x); y = root(y); if (t[x] > t[y]) { swap(x, y); } t[x] += t[y]; t[y] = x; return true; } }; int main() { int64_t n, m, k, sum = 0; cin >> n >> m >> k; vector>> g(m); for (int i = 0; i < m; i++) { int from, to; int64_t cost; cin >> from >> to >> cost; from--; to--; sum += cost; g[i] = {cost, {from, to}}; } union_find uf(n); int64_t mini = 0; for (int i = 0; i < k; i++) { int c; cin >> c; c--; int64_t cost = g[c].first; int from = g[c].second.first, to = g[c].second.second; mini += cost; uf.merge(from, to); } sort(g.begin(), g.end()); for (auto &pp : g) { int64_t cost = pp.first; int from = pp.second.first, to = pp.second.second; if (uf.same(from, to)) { continue; } uf.merge(from, to); mini += cost; } cout << sum - mini << endl; return 0; }