#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; // 最小全域木 O(ElogV)? struct Edge { ll cost, to; bool operator>(const Edge e)const { return this->cost > e.cost; } }; ll Prim(const vector> &G) { ll res = 0; vector used(G.size(), false); priority_queue, greater> pq; for (Edge e : G[0]) { pq.push(e); } used[0] = true; while (!pq.empty()) { Edge e = pq.top(); pq.pop(); if (used[e.to]) continue; used[e.to] = true; res += e.cost; for (Edge u : G[e.to]) { if (used[u.to]) continue; pq.push(u); } } return res; } int main() { int n, m, k; cin >> n >> m >> k; vector> E(m); vector> G(n); ll sum = 0; REP(i, m) { ll a, b, c; cin >> a >> b >> c; a--; b--; E[i] = {a,b,c}; } REP(i, k) { ll e; cin >> e; e--; E[e] = {get<0>(E[e]),get<1>(E[e]),0}; } REP(i, m) { G[get<0>(E[i])].push_back({get<2>(E[i]),get<1>(E[i])}); G[get<1>(E[i])].push_back({get<2>(E[i]),get<0>(E[i])}); sum += get<2>(E[i]); } cout << sum - Prim(G) << endl; getchar(); getchar(); }