#include using namespace std; // one-based numbering struct union_find { vector data; // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent; union_find(int n) { data.resize(n+1, -1); } int find(int x) { if(data[x] < 0) return x; else return data[x] = find(data[x]); } int size(int x) { return -data[find(x)]; } void unite(int x, int y) { x = find(x); y = find(y); if(x == y) return; if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; } bool same(int x, int y) { x = find(x); y = find(y); return x == y; } }; template struct edge { int from, to; Numeric cost; bool operator< (struct edge &e) { return cost < e.cost; } }; template Numeric kruskal(int n, vector< edge > v, union_find u) { sort(v.begin(), v.end()); Numeric mincost = 0; for (int i = 0; i < v.size(); i++) { if (!u.same(v[i].from, v[i].to)){ mincost += v[i].cost; u.unite(v[i].from, v[i].to); } } return mincost; } int main(){ int n, m, k; cin >> n >> m >> k; vector< edge > v(m); long long ans = 0; for (int i = 0; i < m; ++i) { cin >> v[i].from >> v[i].to >> v[i].cost; ans += v[i].cost; } union_find u(n); for (int i = 0; i < k; ++i) { int c; cin >> c; c--; u.unite(v[c].from, v[c].to); ans -= v[c].cost; } cout << ans - kruskal(n, v, u) << endl; return 0; }