#include #include #include #include #define rep(i, n) for(i = 0; i < n; i++) #define int long long using namespace std; typedef tuple T; struct UF { int par[100000]; UF() { int i; rep(i, 100000) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unit(int x, int y) { x = root(x); y = root(y); par[x] = y; } bool same(int x, int y) { return root(x) == root(y); } }; int n, m, k; int a[100000], b[100000], c[100000]; int e[100000]; T edges[100000]; UF uf; signed main() { int i; cin >> n >> m >> k; rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; } rep(i, k) { cin >> e[i]; e[i]--; c[e[i]] = 0; } rep(i, m) { edges[i] = T(c[i], a[i], b[i]); } sort(edges, edges + m); int ans = 0; rep(i, m) { int cst = get<0>(edges[i]); int u = get<1>(edges[i]); int v = get<2>(edges[i]); if (uf.same(u, v)) { ans += cst; } else { uf.unit(u, v); } } cout << ans << endl; return 0; }