1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <bits/stdc++.h> using namespace std;
typedef pair<int, int> pr;
const int N = 1e5 + 666, inf = 214748364;
priority_queue<pr, vector<pr>, greater<pr> >q; int n, m, k, yhm(inf); int c[N], dis[N], vis[N], tag[N];
inline void dij(int now) { int i, x, y, fuck; for (i = 1; i <= n; ++ i) dis[i] = inf, vis[i] = 0; dis[now] = 0, vis[now] = 1; q.push(pr(0, now)); while (! q.empty()) { x = q.top().second; q.pop(); vis[x] = 0; if (tag[x] && x != now) return (void)(yhm = min(yhm, dis[x])); for (i = head[x]; i; i = nex[i]) { y = ver[i]; if (dis[y] > dis[x] + len[i]) { dis[y] = dis[x] + len[i]; if (! vis[y]) { vis[y] = 1; q.push(pr(dis[y], y)); } } } } return; }
signed main() { int i, x, y, z; n = read(), m = read(), k = read(); for (i = 1; i <= m; ++ i) { x = read(), y = read(), z = read(); add_edge(x, y, z); add_edge(y, x, z); } for (i = 1; i <= k; ++ i) c[i] = read(), tag[c[i]] = 1; for (x = 1; x <= k; ++ x) dij(c[x]); put(yhm); return 0; }
|