n, m, k = map(int,input().split()) e = [] for _ in range(m): a, b, c = map(int,input().split()) e.append((a-1,b-1,c)) r = 0 for _ in range(k): i = int(input())-1 a, b, c = e[i] e[i] = (a,b,0) p = list(range(n)) s = [1]*n def f(x): if x == p[x]: return x p[x] = f(p[x]) return p[x] def u(x, y): x = f(x) y = f(y) if s[x] > s[y]: x, y = y, x p[x] = p[y] s[y] += s[x] e.sort(key=lambda x: x[2]) for a, b, c in e: if f(a) == f(b): r += c continue u(a, b) print(r)