#include // c #include // io #include #include #include #include // container #include #include #include #include #include #include // other #include #include #include #include #include using namespace std; using i32=int32_t;using i64=int64_t;using ll =i64;using uint=uint32_t;using ull=uint64_t; template using matrix=vector >; #define ALL(c) (begin(c)),(end(c)) #define REP(i,n) FOR(i,0,n) #define REPr(i,n) FORr(i,0,n) #define FOR(i,l,r) for(int i=(int)(l);i<(int)(r);++i) #define FORr(i,l,r) for(int i=(int)(r)-1;i>=(int)(l);--i) #define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it) #define IN(l,v,r) ((l)<=(v) && (v)<(r)) #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()) //debug #define DUMP(x) cerr << #x << " = " << (x) #define LINE() cerr<< " (L" << __LINE__ << ")" class range { private: struct Iter{ int v; int operator*(){return v;} bool operator!=(Iter& itr) {return v < itr.v;} void operator++() {++v;} }; Iter i, n; public: range(int n) : i({0}), n({n}) {} range(int i, int n) : i({i}), n({n}) {} Iter& begin() {return i;} Iter& end() {return n;} }; //output template ostream& operator << (ostream& os, const vector& as){REP(i,as.size()){if(i!=0)os<<" "; os< ostream& operator << (ostream& os, const vector>& as){REP(i,as.size()){if(i!=0)os< ostream& operator << (ostream& os, const set& ss){for(auto a:ss){if(a!=ss.begin())os<<" "; os< ostream& operator << (ostream& os, const pair& p){os< ostream& operator << (ostream& os, const map& m){bool isF=true;for(auto& p:m){if(!isF)os< ostream& operator << (ostream& os, const tuple& t){os << get<0>(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} //input char tmp[1000]; #define nextInt(n) scanf("%d",&n) #define nextLong(n) scanf("%lld",&n) //I64d #define nextDouble(n) scanf("%lf",&n) #define nextChar(n) scanf("%c",&n) #define nextString(n) scanf("%s",tmp);n=tmp // values template T INF(){assert(false);}; template<> int INF(){return 1<<28;}; template<> ll INF(){return 1LL<<58;}; template<> double INF(){return 1e16;}; template T EPS(){assert(false);}; template<> int EPS(){return 1;}; template<> ll EPS(){return 1LL;}; template<> double EPS(){return 1e-8;}; template<> long double EPS(){return 1e-8;}; template T pfmod(T v,U M){return fmod(fmod(v,M)+M,M);} ll gcd_positive(ll a,ll b) { return b == 0 ? a : gcd_positive(b,a%b); } ll gcd(ll a,ll b) { return gcd_positive(abs(a), abs(b)); } ll lcm(ll a,ll b){return a/gcd(a,b)*b;} namespace EGraph{ typedef ll Cost;Cost CINF=INF(); struct Edge{ int from,to;Cost cost; Edge(int from,int to,Cost cost) : from(from),to(to),cost(cost) {}; bool operator<(Edge r) const{ return cost(Edge r) const{ return cost>r.cost;} }; typedef vector > Graph; } using namespace EGraph; struct UnionFind{ vector par,rank,ss; int size; UnionFind(int n){ REP(i,n) par.push_back(i); rank = vector(n);ss=vector(n,1);size=n; } int root(int x){ if(par[x] == x)return x; return par[x] = root(par[x]); } bool same(int x,int y){ return root(x) == root(y); } void unite(int x,int y){ x = root(x);y = root(y);if(x==y)return; if(rank[x]>rank[y])swap(x,y); par[x] = y;ss[y]+=ss[x]; if(rank[x] == rank[y]) rank[x]++; size--; } int getS(int x){ return ss[root(x)]; } }; class Main{ typedef ll Cost; // E ⊂ S class subset{ private: struct Iter{ ull E,S; ull operator*(){return E;} bool operator!=(Iter& itr) {return E != itr.E || S!=itr.S;} void operator++(){ if((E&(E-1))==0){ E=(E-1)&S;S=E; }else{ E=(E-1)&S; } } }; Iter i, n; public: subset(ull S){ i={S,S};n={0ULL,0ULL}; } Iter& begin() {return i;} Iter& end() {return n;} }; Cost minimum_steiner_tree(const vector& ts, const vector> &g) { const int n = g.size(); if (ts.size() <= 1) return 0; // all-pair shortest vector> ds=g;REP(k,n)REP(i,n)REP(j,n) ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]); vector> dp(1<(n,INF())); REP(i,ts.size())REP(q,n) dp[1 << i][q] = ds[ts[i]][q]; REP(S,1<();REP(q,n)res = min(res,dp[((1 << ts.size())-1)][q]); return res; } public: void run(){ int N,M,T;cin >> N >> M >> T; Graph g = Graph(N); vector es; REP(i,M){ int a,b,c;cin >> a >> b >> c;a--;b--; g[a].push_back(Edge(a,b,c)); g[b].push_back(Edge(b,a,c)); es.push_back(Edge(a,b,c)); } vector vs(T);REP(i,T){cin >> vs[i];vs[i]--;} ull must=0;REP(i,T)must+=1ULL<=16){ //N-T<=19 // 最小全域木 sort(ALL(es)); ll mv=INF(); for(ull bit : subset(opt)){ UnionFind uf=UnionFind(N); ull use=must | bit; Cost res=0; for(Edge& e:es)if(use & (1ULL<> mat(N,vector(N,INF())); REP(i,N)mat[i][i]=0; REP(i,N)EACH(e,g[i])mat[e->from][e->to]=e->cost; cout << minimum_steiner_tree(vs,mat) <