#include #include #include #include #include #include #include #include #include #include using namespace std ; int par[100002]; void init(int n){ for(int i = 0; i < n; i++){ par[i] = i; } } int root(int x){ if(par[x] == x){ return x; }else{ return par[x] = root(par[x]); } } bool same(int x, int y){ return root(x) == root(y); } void unite(int x, int y){ int rx = root(x); int ry = root(y); if(rx == ry) return; par[rx] = ry; } int main(){ int N,M,K; cin >> N >> M >> K; vector >> r; long long int maxcost = 0; for(int i = 0; i < M; i++){ int a,b,c; cin >> a >> b >> c; r.push_back(make_pair(c,make_pair(a,b))); maxcost += c; } init(N); long long int cost = 0; for(int i = 0; i < K; i++){ int e; cin >> e; unite(r[e-1].second.first,r[e-1].second.second); cost += r[e-1].first; } sort(r.begin(), r.end()); for(int i = 0; i < M; i++){ if(!same(r[i].second.first,r[i].second.second)){ unite(r[i].second.first,r[i].second.second); cost += r[i].first; } } cout << maxcost - cost << endl; return 0; }