#include using namespace std; using lint = long long int; template using V = vector; template using VV = V< V >; template void assign(V& v, int n, const T& a = T()) { v.assign(n, a); } template void assign(V& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); } struct QU { V<> par, rank, _size; QU(int n) : par(n), rank(n), _size(n, 1) { iota(par.begin(), par.end(), 0); } int find(int a) { if (par[a] == a) return a; return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int size(int a) { return _size[find(a)]; } void unite(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (rank[a] < rank[b]) { par[a] = b; _size[b] += _size[a]; } else { par[b] = a; _size[a] += _size[b]; } if (rank[a] == rank[b]) rank[a]++; } }; template struct edge { int from, to; T w; edge(int a, int b, T w) : from(a), to(b), w(w) {} }; template T kruskal(V< edge >& g, int n) { T res = 0; QU qu(n); sort(g.begin(), g.end(), [](const auto& a, const auto& b) { return a.w < b.w; }); for (auto&& e : g) { if (!qu.same(e.from, e.to)) { qu.unite(e.from, e.to); res += e.w; } } return res; } int main() { cin.tie(NULL); ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; V< edge > g; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c, a--, b--; g.emplace_back(a, b, c); } QU qu(n); lint res = 0; for (int i = 0; i < k; i++) { int e; cin >> e, e--; res += g[e].w; qu.unite(g[e].from, g[e].to); } sort(g.begin(), g.end(), [](const auto& a, const auto& b) { return a.w < b.w; }); lint s = 0; for (auto&& e : g) { s += e.w; if (!qu.same(e.from, e.to)) { res += e.w; qu.unite(e.from, e.to); } } cout << s - res << '\n'; }