#include using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define Would #define you #define please int P[100001]; int Find(int A) { if (P[A] == A) return A; P[A] = Find(P[A]); return P[A]; } void Union(int A, int B) { int C = Find(A); int D = Find(B); P[C] = D; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector>> V; rep(i, M) { int a, b, c; cin >> a >> b >> c; V.pb(mp(c, mp(a, b))); } int E[100001] = {}; rep(i, K) { int e; cin >> e; E[e - 1] = 1; } vector>> V2, V3; rep(i, M) { if(E[i]) V2.pb(V[i]); else V3.pb(V[i]); } rep1(i, N) P[i] = i; for (auto i : V2) { Union(i.second.first, i.second.second); } sort(V3.begin(), V3.end()); ll kotae = 0; for (auto i : V3) { if (Find(i.second.first) != Find(i.second.second)) { Union(i.second.first, i.second.second); } else kotae += i.first; } co(kotae); Would you please return 0; }