提交时间:2025-11-26 17:44:17

运行 ID: 38966

#include <algorithm> #include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; using i64 = long long; constexpr i64 INF = 0x3f3f3f3f3f3f3f3f; int n; vector<bool> special; vector<vector<pair<int, int>>> graph; i64 find_closest(int start) { priority_queue<pair<i64, int>> nodes; vector<bool> vis(n + 1); nodes.emplace(0, start); while (!nodes.empty()) { auto [dis, u] = nodes.top(); nodes.pop(); if (vis[u]) continue; if (dis != 0 && special[u]) return -dis; vis[u] = true; for (auto [v, w] : graph[u]) nodes.emplace(dis - w, v); } return INF; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int m, T; cin >> n >> m >> T; graph.resize(n + 1); for (int i = 0; i < m; ++i) { int u, v, w; cin >> u >> v >> w; graph[u].emplace_back(v, w); graph[v].emplace_back(u, w); } special.resize(n + 1); for (int i = 0; i < T; ++i) { int u; cin >> u; special[u] = true; } i64 ans = INF; for (int i = 1; i <= n; ++i) { if (special[i]) ans = min(ans, find_closest(i)); } cout << ans << endl; return 0; }