#include using namespace std; struct UnionFind{ vector data; UnionFind(int size) : data(size, -1){} void unite(int x, int y){ x = root(x); y = root(y); if (x != y){ if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } } int root(int x) {return data[x] < 0 ? x : data[x] = root(data[x]);} int size(int x) {return -data[root(x)];} }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector> edges(M, pair()); vector> cs(N, pair()); vector es(K, 0); long long total_cost = 0; for (int i = 0; i < M; ++i){ int a, b, c; cin >> a >> b >> c; edges[i] = make_pair(a-1, b-1); cs[i] = make_pair(c, i); total_cost += c; } for (auto &e: es) cin >> e; UnionFind uf(N); long long cost = 0; for (auto e: es){ cost += cs[e - 1].first; uf.unite(edges[e-1].first, edges[e-1].second); } sort(cs.begin(), cs.end()); for (auto &ci: cs){ int i = ci.second; int a = edges[i].first; int b = edges[i].second; if (uf.root(a) == uf.root(b)) continue; cost += ci.first; uf.unite(a, b); } cout << total_cost - cost << endl; return 0; }