/* Train of Thought: the shortest path for multiple source points and multiple meeting points! Use the node with the minimum number-1 but the most source point as the sink point! Change the problem into the shortest path from a source point to a sink point! I forgot to initialize vector many times .... potholes */# include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <vector> # define M 1100 # define INF 0x3f3f3fusing namespace STD; struct node {int V; int tt; node () {} node (int v, int TT) {This-> V = V; this-> TT = tt ;}}; vector <node> V [m]; int d [m], vis [m]; int City [m]; int N; int T, S, D; void Dijkstra () {memset (D, 0x3f, sizeof (d); memset (VIS, 0, sizeof (VIS); D [0] = 0; vis [0] = 1; int root = 0; For (Int J = 0; j <= N; ++ J) {int minlen = inf, P, len = V [root]. size (); For (INT I = 0; I <Len; ++ I) {int u = V [root] [I]. v; If (! Vis [u] & D [u]> d [root] + V [root] [I]. TT) d [u] = d [root] + V [root] [I]. TT ;}// update the distance between all nodes connected to the root node for (INT I = 0; I <= n + 1; ++ I) // The shortest distance from 0 nodes to all nodes! If (! Vis [I] & minlen> d [I]) {P = I; minlen = d [I];} If (minlen = inf) return; root = P; vis [root] = 1 ;}} int main () {While (CIN> S> T> d) {int A, B, T; n =-1; while (s --) {CIN> A> B> T; V [A]. push_back (node (B, T); V [B]. push_back (node (A, T); n = max (n, max (A, B);} while (t --) {CIN>; V [0]. push_back (node (A, 0); V [A]. push_back (node (0, 0); n = max (n, a) ;}for (INT I = 1; I <= D; ++ I) {CIN> City [I]; n = max (n, City [I]);} For (INT I = 1; I <= D; ++ I) {v [n + 1]. push_back (node (City [I], INF); V [City [I]. push_back (node (n + 1, 0);} Dijkstra (); For (INT I = 0; I <= n + 1; ++ I) V [I]. clear (); cout <D [n + 1] <Endl;} return 0 ;}