#include //#include using namespace std; // using namespace boost::multiprecision; // Define using ll = long long; using ull = unsigned long long; using ld = long double; using int128 = __int128; // using cint = cpp_int; const ll MOD = 1e9 + 7; const ll INF = LONG_MAX; const ull MAX = ULONG_MAX; #define endl '\n' #define space ' ' #define def inline auto #define func inline constexpr ll #define run __attribute__((constructor)) def _ #define all(v) begin(v), end(v) // Debug #define debug(...) \ { \ cerr << __LINE__ << ": " << #__VA_ARGS__ << " = "; \ for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] "; \ cerr << endl; \ } // Loop #define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i) #define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i) #define each(i, a) for (auto &&i : a) #define rep(i, n) inc(i, 0, n - 1) // Stream #define input(a) scanf("%lld", &(a)) #define output(a) printf("%lld\n", (a)) #define fout(n) cout << fixed << setprecision(n) #define fasten cin.tie(0), ios::sync_with_stdio(0) // Speed run() { fasten, fout(10); } #pragma GCC optimize("O3") #pragma GCC optimization_level 3 #pragma GCC target("avx") // Math func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } func lcm(ll a, ll b) { return a * b / gcd(a, b); } #define fst first #define snd second #define int ll struct edge { int src, dst; int weight; }; struct graph { int n; vector edges; graph(int n = 0) : n(n) { p.assign(n, -1); } void add_edge(int src, int dst, int weight) { n = max(n, max(src, dst) + 1); edges.push_back({src, dst, weight}); } vector p; int root(int i) { return p[i] < 0 ? i : p[i] = root(p[i]); } bool unite(int i, int j) { if ((i = root(i)) == (j = root(j))) return false; if (p[i] > p[j]) swap(i, j); p[i] += p[j]; p[j] = i; return true; } int kruskal() { sort(all(edges), [](edge x, edge y) { return x.weight < y.weight; }); int result = 0; for (auto e : edges) if (unite(e.src, e.dst)) result += e.weight; return result; } }; signed main() { ll N, M, K, A[100000][3], E, S = 0; cin >> N >> M >> K; graph g(N); rep(i, M) rep(j, 3) cin >> E, A[i][j] = E - bool(j - 2); rep(i, K) cin >> E, A[E - 1][2] = 0, g.unite(A[E - 1][0], A[E - 1][1]); rep(i, M) { S += A[i][2]; g.add_edge(A[i][0], A[i][1], A[i][2]); } debug(S); cout << S - g.kruskal() << endl; } // for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17