#include #define FOR(v, a, b) for(int v = (a); v < (b); ++v) #define FORE(v, a, b) for(int v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for(int v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define LLI long long int using namespace std; template using V = vector; template using P = pair; template P operator+(const P &a, const P &b){return {a.first + b.first, a.second + b.second};} template P operator-(const P &a, const P &b){return {a.first - b.first, a.second - b.second};} class UnionFind{ vector parent, depth, size; public: UnionFind(int n): parent(n), depth(n,1), size(n,1){REP(i, n) parent[i] = i;} int getRoot(int i){ if(parent[i] == i) return i; else return parent[i] = getRoot(parent[i]); } bool isSame(int i, int j){return getRoot(i) == getRoot(j);} void merge(int i, int j){ int ri = getRoot(i), rj = getRoot(j); if(ri != rj){ if(depth[ri] < depth[rj]){ parent[ri] = rj; size[rj] += size[ri]; }else{ parent[rj] = ri; size[ri] += size[rj]; if(depth[ri] == depth[rj]) ++depth[ri]; } } } int getSize(int i){return size[getRoot(i)];} }; int N,M,K; vector e; template vector> kruskal(int n, vector> &graph){ UnionFind uf(n); REP(i,K) uf.merge(get<0>(graph[e[i]]), get<1>(graph[e[i]])); vector> mst; REP(i,K) mst.push_back(graph[e[i]]); sort(graph.begin(), graph.end(), [](tuple &a, tuple &b){return get<2>(a) < get<2>(b);}); for(auto v : graph){ int s,t,d; tie(s,t,d) = v; if(!uf.isSame(s,t)){ uf.merge(s,t); mst.push_back(v); } } return mst; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M >> K; vector> graph; int cost = 0; REP(i,M){ int a,b,c; cin >> a >> b >> c; graph.push_back(make_tuple(a-1,b-1,c)); cost += c; } e.resize(K); REP(i,K){cin >> e[i]; e[i]--;} vector> res = kruskal(N, graph); int ans = 0; REP(i,res.size()){ //cout << get<0>(res[i]) << " " << get<1>(res[i]) << " " << get<2>(res[i]) << endl; ans += get<2>(res[i]); } cout << cost-ans << endl; return 0; }