#include #include #include using namespace std; struct DSU { vector dat; DSU(int n) : dat(n, -1) {} int find(int u) { if (dat[u] < 0) return u; return dat[u] = find(dat[u]); } bool unite(int u, int v) { u = find(u); v = find(v); if (u == v) return false; if (dat[u] > dat[v]) swap(u, v); dat[u] += dat[v]; dat[v] = u; return true; } }; int main() { int n, m, k; cin >> n >> m >> k; vector> es(m); vector us(m), vs(m); long long ans = 0; for (int i = 0; i < m; i++) { int c; cin >> us[i] >> vs[i] >> c; es[i] = make_pair(c, i); } DSU dsu(n + 1); vector can(m, true); for (int i = 0; i < k; i++) { int e; cin >> e; e--; can[e] = false; dsu.unite(us[e], vs[e]); } sort(es.begin(), es.end()); for (auto e : es) { if (!can[e.second]) continue; if (!dsu.unite(us[e.second], vs[e.second])) { ans += e.first; } } cout << ans << endl; }