#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int N,M,K,R[5]; vector>> G[200]; long long dp[200][1 << 5]; void solve() { cin >> N >> M >> K; for(int i = 0;i < K;i++) cin >> R[i],R[i]--; sort(R,R+K); int id = 0; for(int i = 0;i < M;i++) { int u,v,w; cin >> u >> v >> w; u--; v--; int x = 0; if(id < K && R[id] == i) x |= 1 << id,id++; G[u].push_back(make_pair(v,make_pair(w,x))); G[v].push_back(make_pair(u,make_pair(w,x))); } assert(id == K); for(int i = 0;i < N;i++)for(int j = 0;j < 1 << K;j++) dp[i][j] = (long long)1e18; dp[0][0] = 0; priority_queue>> Q; Q.push(make_pair(-0,make_pair(0,0))); while(!Q.empty()) { long long cur = -Q.top().first; auto [u,s] = Q.top().second; Q.pop(); if(dp[u][s] < cur) continue; for(auto [v,wx]:G[u]) { int ns = s | wx.second; if(dp[v][ns] > dp[u][s]+wx.first) { dp[v][ns] = dp[u][s]+wx.first; Q.push(make_pair(-dp[v][ns],make_pair(v,ns))); } } } cout << dp[N-1][(1 << K)-1] << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; //cin >> tt; while(tt--) solve(); }