#include #include #include using namespace std; typedef long long LL; const int N = 100010, M = 2 * N; struct Line { int a, b, c; }; LL ans, tot; vector vec; int n, m, kk, fa[N]; int Find(int x) { if (fa[x] != x) fa[x] = Find(fa[x]); return fa[x]; } void Kruskal() { sort(vec.begin(), vec.end(), [](Line l1, Line l2) { return l1.c < l2.c; }); for (auto [a, b, c] : vec) { int fx = Find(a), fy = Find(b); if (fx != fy) { fa[fx] = fy; ans += c; } } } int main() { // freopen("cost.in", "r", stdin); // freopen("cost.out", "w", stdout); scanf("%d%d%d", &n, &m, &kk); vec.resize(m); for (int i = 0; i < m; ++i) { scanf("%d%d%d", &vec[i].a, &vec[i].b, &vec[i].c); tot += vec[i].c; } for (int i = 1; i <= n; ++i) fa[i] = i; for (int i = 1, x; i <= kk; ++i) { scanf("%d", &x); --x; int fx = Find(vec[x].a), fy = Find(vec[x].b); fa[fx] = fy; ans += vec[x].c; } Kruskal(); printf("%lld\n", tot - ans); return 0; }