#include #define SELECTER(_1,_2,_3,SELECT,...) SELECT #define rep1(i,n) for(int i=0;i<(int)n;++i) #define rep2(i,a,n) for(int i=(int)a;i<(int)n;++i) #define rep(...) SELECTER(__VA_ARGS__,rep2,rep1) (__VA_ARGS__) #define fi first #define se second using namespace std; using ll=long long; using pii=pair; using pll=pair; using veci=vector; using vecpii=vector>; using vecll=vector; using vecpll=vector>; using vecs=vector; using vecb=vector; using vecd=vector; template inline bool chmax(T& a,T b){if(a inline bool chmin(T& a,T b){if(a>b) {a=b;return true;} return false;} constexpr double PI=3.14159265359; constexpr int iMAX=2147483647; constexpr ll lMAX=9223372036854775807; //constexpr int INF=1<<30; constexpr ll INF=1LL<<60; //constexpr int MOD=1000000007; //constexpr ll MOD=1000000007; constexpr ll MOD=998244353; //constexpr int LOG=62; struct UnionFind{ veci par_size; int _n; UnionFind(int n):_n(n),par_size(n,-1){} int root(int a){ assert(0 <= a && a < _n); if(par_size[a]<0) return a; return par_size[a]=root(par_size[a]); } void unite(int a,int b){ assert(0 <= a && a < _n); assert(0 <= b && b < _n); int ra=root(a);int rb=root(b); if(ra==rb) return; if(-par_size[ra]<-par_size[rb]) swap(ra,rb); par_size[ra]+=par_size[rb]; par_size[rb]=ra; } bool same(int a,int b){ assert(0 <= a && a < _n); assert(0 <= b && b < _n); return root(a)==root(b); } int size(int a) { assert(0 <= a && a < _n); return -par_size[root(a)]; } vector groups() { veci leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = root(i); group_size[leader_buf[i]]++; } vector result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( remove_if(result.begin(), result.end(), [&](const veci& v) {return v.empty();}), result.end()); return result; } }; int main(){ //ifstream in("input.txt"); //cin.rdbuf(in.rdbuf()); int n,m,k;cin>>n>>m>>k; veci a(m),b(m),c(m); ll sum=0; rep(i,m) { cin>>a[i]>>b[i]>>c[i]; a[i]--;b[i]--; } UnionFind uni(n); vecb used(m,false); rep(i,k){ int v;cin>>v; v--; uni.unite(a[v],b[v]); used[v]=true; } priority_queue,vector>,greater>> que; rep(i,m){ if(!used[i]) que.emplace(c[i],pii{a[i],b[i]}); } ll ans=0; while(que.size()){ int cv=que.top().fi; pii v=que.top().se; que.pop(); if(uni.same(v.fi,v.se)) {ans+=cv;continue;} uni.unite(v.fi,v.se); } cout<