#include #include #include #include #include #include #include using namespace std; using ll = long long; struct UnionFind { UnionFind(int n) : p(n, -1) {} int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); } bool same(int u, int v) { return root(u) == root(v); } void unite(int u, int v) { u = root(u); v = root(v); if (u == v) return; if (p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; } vector p; }; struct Edge { bool operator<(Edge o) { return c < o.c; } int i, j; int c; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; ll r = 0; vector e(m); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; e[i] = { a, b, c }; r += e[i].c; } UnionFind uf(n); for (int j = 0; j < k; j++) { int i; cin >> i; i--; uf.unite(e[i].i, e[i].j); r -= e[i].c; } sort(e.begin(), e.end()); for (int i = 0; i < m; i++) { if (uf.same(e[i].i, e[i].j)) continue; uf.unite(e[i].i, e[i].j); r -= e[i].c; } cout << r << endl; return 0; }