#include #include #include #include template struct Edge { int src, dst; Cost cost; Edge(int src = -1, int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge& e) const { return this->cost < e.cost; } bool operator>(const Edge& e) const { return this->cost > e.cost; } }; template using Edges = std::vector>; struct UnionFind { std::vector par, sz; int gnum; explicit UnionFind(int n) : par(n), sz(n, 1), gnum(n) { std::iota(par.begin(), par.end(), 0); } int find(int v) { return (par[v] == v) ? v : (par[v] = find(par[v])); } void unite(int u, int v) { u = find(u), v = find(v); if (u == v) return; if (sz[u] < sz[v]) std::swap(u, v); sz[u] += sz[v]; par[v] = u; --gnum; } bool same(int u, int v) { return find(u) == find(v); } bool ispar(int v) { return v == find(v); } int size(int v) { return sz[find(v)]; } }; using lint = long long; void solve() { int n, m, k; std::cin >> n >> m >> k; Edges es(m); lint esum = 0; for (auto& e : es) { std::cin >> e.src >> e.dst >> e.cost; --e.src, --e.dst; esum += e.cost; } lint ans = 0; UnionFind uf(n); while (k--) { int ei; std::cin >> ei; const auto& e = es[--ei]; ans += e.cost; uf.unite(e.src, e.dst); } std::sort(es.begin(), es.end()); for (const auto& e : es) { if (uf.same(e.src, e.dst)) continue; ans += e.cost; uf.unite(e.src, e.dst); } std::cout << esum - ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }