#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() #include using namespace atcoder; const ll INF = 1ll << 60; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector>> E(M); ll ans = 0; rep(i, 0, M) { cin >> E[i].second.first >> E[i].second.second >> E[i].first; E[i].second.first--; E[i].second.second--; ans += E[i].first; } dsu uf(N); rep(i, 0, K) { int e; cin >> e; e--; uf.merge(E[e].second.first, E[e].second.second); ans -= E[e].first; E[e].first = INF; } sort(all(E)); while (true) { if (E.back().first == INF) E.pop_back(); else break; } rep(i, 0, E.size()) { if (!uf.same(E[i].second.first, E[i].second.second)) { uf.merge(E[i].second.first, E[i].second.second); ans -= E[i].first; } } cout << ans << '\n'; }