#include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; struct UnionFind { vector par; vector rank; UnionFind(int n) { par.resize(n); rep(i, n) par[i] = i; rank.resize(n, 0); } int find(int i) { if (i == par[i]) return par[i]; else return par[i] = find(par[i]); } void unite(int i, int j) { i = find(i), j = find(j); if (i == j) return; if (rank[i] < rank[j]) { par[i] = j; } else { par[j] = i; if (rank[i] == rank[j]) rank[i]++; } } bool same(int i, int j) { return find(i) == find(j); } }; int main() { int n, m, k; cin >> n >> m >> k; struct Edge { int a, b, c; }; vector edges; rep(_, m) { int a, b, c; cin >> a >> b >> c; edges.push_back(Edge{a - 1, b - 1, c}); } long long sum = 0; UnionFind uf(n); rep(_, k) { int i; cin >> i; uf.unite(edges[i - 1].a, edges[i - 1].b); sum += (long long)edges[i - 1].c; } vector edges2; rep(i, m) { auto a = uf.find(edges[i].a), b = uf.find(edges[i].b); if (a != b) edges2.push_back(Edge{a, b, edges[i].c}); } sort(edges2.begin(), edges2.end(), [&](const auto &l, const auto &r) { return l.c < r.c; }); UnionFind uf2(n); for (auto e : edges2) { if (!uf.same(e.a, e.b)) { uf.unite(e.a, e.b); sum += (long long)e.c; } } auto tot = accumulate( edges.begin(), edges.end(), 0LL, [&](long long res, const auto &e) { return res + (long long)e.c; }); cout << tot - sum << endl; return 0; }