#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> using namespace std; const int INF = 0x7fffffff; const int maxn = 1100; struct Edge { int from, to, dist; }; // struct HeapNode { int d, u; bool operator < (const HeapNode& rhs)const { return d > rhs.d; } }; int n, m;//point, edge vector<Edge> edges; vector<int> G[maxn]; bool done[maxn]; int d[maxn]; //int p[maxn]; int term[maxn]; void init() { for(int i = 0; i < maxn; i++) G[i].clear();//節點從1開始編號。 edges.clear(); // memset(p, 0, sizeof(p)); } void AddEdge(int from, int to, int dist) {//注意是無向圖,WA了好多次。 edges.push_back((Edge){from, to, dist}); m = edges.size();//edges G[from].push_back(m-1);//給每個邊編號從0開始。 } void Dijkstra() { priority_queue<HeapNode> Q; for(int i = 0; i <= maxn; i++){ //n,節點的編號並非為n d[i] = INF; } d[0] = 0;//用節點作為超級源點。 memset(done, 0, sizeof(done)); Q.push((HeapNode){0, 0});//d, u while(!Q.empty()) { HeapNode x = Q.top(); Q.pop(); int u = x.u; if(done[u]) continue; done[u] = true;//標記已一個。經訪問過且為解中的頂點 for(int i = 0; i < (int)G[u].size(); i++) { Edge& e = edges[G[u][i]]; if(d[e.to] > d[u] + e.dist) { d[e.to] = d[u] + e.dist; // p[e.to] = G[u][i]; //記錄前驅節點編號。 Q.push((HeapNode){d[e.to], e.to}); } } } } int main() { int T, S, D; n = maxn; while(scanf("%d%d%d", &T, &S, &D) != EOF) {//start, destination init(); for(int i = 0; i < T; i++) { int from, to, dist; scanf("%d%d%d", &from, &to, &dist); AddEdge(from, to, dist); AddEdge(to, from, dist); } for(int i = 0; i < S; i++) { int to; scanf("%d", &to); AddEdge(0, to, 0); } for(int i = 0; i < D; i++) { scanf("%d", &term[i]); } Dijkstra(); int res = INF; for(int i = 0; i < D; i++) { if(d[term[i]]<res) res = d[term[i]]; } printf("%d\n", res); } return 0; }