#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; struct edge{ int from,to; ll cost; edge(int cost,int from,ll to):cost(cost),from(from),to(to){} bool operator< (const edge &right){ return cost < right.cost;} bool operator> (const edge &right){ return cost > right.cost;} bool operator<= (const edge &right){ return cost <= right.cost;} bool operator>= (const edge &right){ return cost >= right.cost;} }; struct Unionfind{ vector parents; int m; Unionfind(int n):parents(n,-1){ m = n; } int find(int x){ if(parents.at(x) < 0){ return x; }else{ parents.at(x) = find(parents.at(x)); return parents.at(x); } } void unite(int x,int y){ x = find(x); y = find(y); if(x==y) return; if(parents.at(x) > parents.at(x))swap(x,y); parents.at(x) += parents.at(y); parents.at(y) = x; } int size(int x){ return -parents.at(find(x)); } bool same(int x,int y){ return find(x) ==find(y); } vector members(int x){ int root = find(x); vector A; for(int i=0;i EG; int n,m,k; cin >> n >> m >>k; vector a(m),b(m); vector c(m); ll sum = 0; rep(i,m){ cin >> a[i] >> b[i] >> c[i]; --a[i];--b[i]; sum += c[i]; EG.push_back(edge(c[i],a[i],b[i])); } Unionfind uf(n); ll res = 0; rep(i,k){ int e; cin >> e; --e; uf.unite(a[e],b[e]); res += c[e]; EG[e].cost = LINF; } sort(EG.begin(),EG.end()); for(edge eg:EG){ if(uf.same(eg.from,eg.to)) continue; uf.unite(eg.from,eg.to); res += eg.cost; } cout << sum - res << endl; return 0; }