#include <bits/stdc++.h> using namespace std; int tarif, k, start, n; vector<pair<int, int>> G[100001]; int Imp[20], Dist[20][20], D[100001], DP[70000]; priority_queue<pair<int, int>> 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<int> 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<<i)<=conf; i++) { if(conf & (1 << i)) Need.push_back(i + 1); } int best = 1e9; do { int cand = Dist[0][Need[0]]; for(int i=1; i<Need.size(); i++) cand += Dist[Need[i-1]][Need[i]]; best = min(best, cand); } while(next_permutation(Need.begin(), Need.end())); return Cost[conf] = tarif + best; } int main() { int t, a, b, c, m; cin >> 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; }