#include using namespace std; #define int long long struct Edge { int u, v, w; bool operator<(const Edge& R) const { return w < R.w; } }; const int MAXN = 100010; int n, m, k; Edge e[MAXN]; int fa[MAXN]; void init(int n) { for (int i = 1; i <= n; ++i) { fa[i] = i; } } int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } bool unite(int u, int v) { u = find(u); v = find(v); if (u == v) return false; fa[u] = v; return true; } long long kur() { sort(e, e + m); // ?1???? init(n); // ????????K?? int edgeCount = 0; long long mstWeight = 0; // ?????????????? for (int i = 0 ; i < m; ++i) { if (e[i].w == 0) { // ????????????0? if (unite(e[i].u, e[i].v)) { edgeCount++; // ?????sumw???????????? } } } // ?????????????? for (int i = 1; i <= m; ++i) { if (e[i].w != 0) { // ???????? if (unite(e[i].u, e[i].v)) { mstWeight += e[i].w; edgeCount++; } } } // ????????? return (edgeCount == n - 1) ? mstWeight : -1; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; // ????? for (int i = 1; i <= m; ++i) { cin >> e[i].u >> e[i].v >> e[i].w; } // ???????? vector required(m + 1, false); for (int i = 1; i <= k; ++i) { int x; cin >> x; required[x] = true; } // ??????????????????0 long long totalWeight = 0; for (int i = 1; i <= m; ++i) { totalWeight += e[i].w; if (required[i]) { e[i].w = 0; // ???????????0 } } long long mstWeight = kur(); if (mstWeight == -1) { // ????????????????? cout << 0 << endl; } else { // ????????? = ??? - ??????? cout << totalWeight - mstWeight << endl; } return 0; }