#include #include #include using namespace std; struct edge { int a, b, cost; }; int par[100009]; int root(int x) { if (x == par[x]) return x; return par[x] = root(par[x]); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector g; long long sumlength = 0; for (int i = 0; i < M; ++i) { int a, b, c; cin >> a >> b >> c; --a, --b; sumlength += c; g.push_back(edge{ a, b, c }); } vector use(M); for (int i = 0; i < K; ++i) { int x; cin >> x; --x; use[x] = true; } for (int i = 0; i < N; ++i) par[i] = i; vector edgelist; for (int i = 0; i < M; ++i) { if (use[i]) { par[root(g[i].a)] = root(g[i].b); sumlength -= g[i].cost; } else { edgelist.push_back(g[i]); } } sort(edgelist.begin(), edgelist.end(), [](edge e1, edge e2) { return e1.cost < e2.cost; }); for (edge e : edgelist) { if (root(e.a) != root(e.b)) { par[root(e.a)] = root(e.b); sumlength -= e.cost; } } cout << sumlength << '\n'; return 0; }