#include using namespace std; signed main() { ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector> E(M); for (int i = 0; i < M; ++i) { int u, v, w; cin >> u >> v >> w; E[i] = make_tuple(w, u - 1, v - 1); } set taken; for (int i = 0; i < K; ++i) { int e; cin >> e; taken.emplace(e - 1); } vector fa(N); iota(fa.begin(), fa.end(), 0); function find = [&](int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }; auto unite = [&](int x, int y) { int a = find(x); int b = find(y); if (a == b) return false; fa[a] = b; return true; }; int64_t ans = 0; for (int i = 0; i < M; ++i) ans += get<0>(E[i]); for (int i : taken) { int w, u, v; tie(w, u, v) = E[i]; unite(u, v); ans -= w; } vector eord(M); iota(eord.begin(), eord.end(), 0); sort(eord.begin(), eord.end(), [&](int i, int j) { return get<0>(E[i]) < get<0>(E[j]); }); for (int i = 0; i < M; ++i) { if (taken.count(eord[i])) continue; int w, u, v; tie(w, u, v) = E[eord[i]]; if (unite(u, v)) ans -= w; } cout << ans << endl; return 0; }