#include using namespace std; int tarif, k, start, n; vector> G[100001]; int Imp[20], Dist[20][20], D[100001], DP[70000]; priority_queue> Q; void Dijkstra(int start) { for(int i=1; i<=n; i++) D[i] = 1e9; D[start] = 0; Q.push({0, start}); while(!Q.empty()) { auto top = Q.top(); Q.pop(); if(-top.first != D[top.second]) continue; for(auto e : G[top.second]) { if(D[e.first] > D[top.second] + e.second) { D[e.first] = D[top.second] + e.second; Q.push({-D[e.first], e.first}); } } } } int countBits(int conf) { if(conf == 0) return 0; return 1 + countBits(conf ^ (conf & -conf)); } vector Need; bool Comp[100000]; int Cost[100000]; int getCost(int conf) { if(Comp[conf]) return Cost[conf]; Comp[conf] = 1; Need.clear(); for(int i=0; (1<> n >> m; while(m--) { cin >> t >> a >> b >> c; G[a].push_back({b, c}); if(t == 2) G[b].push_back({a, c}); } cin >> tarif >> Imp[0] >> k; for(int i=1; i<=k; i++) cin >> Imp[i]; for(int i=0; i<=k; i++) { Dijkstra(Imp[i]); for(int j=0; j<=k; j++) Dist[i][j] = D[Imp[j]]; } for(int conf=1; conf<(1 << k); conf++) { DP[conf] = 1e9; for(int sub=conf; sub; sub=((sub-1)&conf)) { if(countBits(sub) <= 4) { DP[conf] = min(DP[conf], DP[conf & (~sub)] + getCost(sub)); } } } cout << DP[(1 << k) - 1]; return 0; }