// yukicoder: No.748 yuki国のお財布事情 // bal4u 2019.8.19 #include #include typedef long long ll; //// 入出力関係 #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } #define MAX 100005 /* UNION-FIND library */ int id[MAX], size[MAX]; void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; } int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; } int connected(int p, int q) { return root(p) == root(q); } void unite(int p, int q) { int i = root(p), j = root(q); if (i == j) return; if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j]; } typedef struct { int a, b, c; char f; } EDGE; // 道路の両端町、維持費、維持指定フラグ EDGE e[MAX]; int M; EDGE edge[MAX]; int sz; int cmp(const void *u, const void *v) { return ((EDGE *)u)->c - ((EDGE *)v)->c; } ll kruskal(int E) { int i; ll ans = 0; qsort(edge, E, sizeof(EDGE), cmp); for (i = 0; i < E; i++) { if (!connected(edge[i].a, edge[i].b)) { unite(edge[i].a, edge[i].b); ans += edge[i].c; } } return ans; } int main() { int i, N, K; ll cost, new; N = in(), M = in(), K = in(); cost = 0; for (i = 1; i <= M; i++) { e[i].a = in(), e[i].b = in(), e[i].c = in(); cost += e[i].c; } while (K--) e[in()].f = 1; new = 0, sz = 0; init(N+1); // UNION-FIND 初期化 for (i = 1; i <= M; i++) { if (e[i].f) { new += e[i].c; unite(e[i].a, e[i].b); } else edge[sz++] = e[i]; } printf("%lld\n", cost-new-kruskal(sz)); return 0; }