#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } #include int main() { int n, m, k; cin >> n >> m >> k; auto g = vec>(uns, n, 0); auto e = vec>(uns, m); for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; --a; --b; g[a].push_back({ b, c }); g[b].push_back({ a, c }); e[i] = { a, b, c }; } int64_t sum = 0; for (auto [a, b, c] : e) { sum += c; } atcoder::dsu dsu(n); for (int i = 0; i < k; ++i) { int f; cin >> f; --f; auto [a, b, c] = e[f]; dsu.merge(a, b); sum -= c; } auto groups = dsu.groups(); auto b = vec(uns, n); int count = 0; for (auto _ : groups) { for (auto v : _) { b[v] = count; } ++count; } auto f = vec>(uns, 0); for (auto _ : groups) { int r = _[0]; for (auto v : _) { for (auto [u, c] : g[v]) { if (dsu.same(r, u)) { continue; } f.push_back({ b[v], b[u], c }); } } } sort(begin(f), end(f), [](auto x, auto y) { return get<2>(x) < get<2>(y); }); dsu = atcoder::dsu(size(groups)); for (auto [a, b, c] : f) { if (dsu.same(a, b)) { continue; } dsu.merge(a, b); sum -= c; } cout << sum << endl; }