#include #include #include #include #define repi(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define all(a) (a).begin(), (a).end() typedef long long ll; const int MAX_N = 35, INF = 1<<28; int N, M, T; int d[MAX_N][MAX_N], opt[1<<16][MAX_N]; std::vector ts; ll Tvs; struct UnionFind { std::vector par, rank; UnionFind( std::size_t sz ) : par(sz), rank(sz) { std::iota( all(par), 0 ); } int find( int x ) { return x==par[x] ? x : par[x]=find(par[x]); } void unite( int x, int y ) { x = find(x); y = find( y ); if( x == y ) return; if( rank[x] < rank[y] ) par[x] = y; else { par[y] = x; if( rank[x] == rank[y] ) ++rank[x]; } return; } bool same( int x, int y ) { return find(x) == find(y); } }; struct edge { int from, to, cost; edge( int from, int to, int cost ) : from(from), to(to), cost(cost) {} bool operator< ( const edge &e ) { return cost < e.cost; } }; std::vector es; int main() { scanf( "%d%d%d", &N, &M, &T ); rep( i, N ) rep( j, N ) d[i][j] = i==j?0:INF; rep( i, M ) { int a, b, c; scanf( "%d%d%d", &a, &b, &c ); --a; --b; d[a][b] = d[b][a] = c; es.push_back( edge( a, b, c ) ); } rep( i, T ) { int v; scanf( "%d", &v ); ts.push_back(--v); Tvs |= 1ll<= 0; --S ) { S &= Tvs; UnionFind uf(N); int cost = 0; rep( i, es.size() ) { const edge &e = es[i]; if( S>>e.from&1 || S>>e.to&1 ) continue; if( !uf.same( e.from, e.to ) ) { cost += e.cost; uf.unite( e.from, e.to ); } } ans = std::min( ans, cost ); } } printf( "%d\n", ans ); return 0; }