#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>N>>M>>T; FOR(i,M) { cin>>A[i]>>B[i]>>C[i]; mat[A[i]-1][B[i]-1]=mat[B[i]-1][A[i]-1]=C[i]; } FOR(i,N) FOR(x,N) FOR(y,N) mat[x][y]=min(mat[x][y],mat[x][i]+mat[i][y]); FOR(i,T) cin>>V[i], V[i]--, ok[V[i]]=1; priority_queue > Q; FOR(x,N) FOR(y,N) if(x!=y && ok[x]&&ok[y]) Q.push(make_pair(-mat[x][y],x*100+y)); int tot=0; while(Q.size()) { pair p=Q.top(); Q.pop(); x=p.second/100, y=p.second%100; if(uf[x]!=uf[y]) { tot+=-p.first; uf.unite(x,y); } } cout<