From 9a2b00f2744e6faa27ddd15ac5f000e9f9e816c0 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 3 Aug 2021 19:28:01 +0800 Subject: [PATCH] =?UTF-8?q?P6770=20[USACO05MAR]Checking=20an=20Alibi=20?= =?UTF-8?q?=E4=B8=8D=E5=9C=A8=E5=9C=BA=E7=9A=84=E8=AF=81=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R54888422 --- Luogu/problem/P6770/P6770.cpp | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Luogu/problem/P6770/P6770.cpp diff --git a/Luogu/problem/P6770/P6770.cpp b/Luogu/problem/P6770/P6770.cpp new file mode 100644 index 00000000..150db624 --- /dev/null +++ b/Luogu/problem/P6770/P6770.cpp @@ -0,0 +1,47 @@ +#include + +using namespace std; + +int f, p, c, m, u, v, w, x, dist[505]; +bool vis[505]; +vector> g[505]; +priority_queue, greater> ans; + +void dijkstra() { + memset(dist, 0x3f, sizeof(dist)); + priority_queue, vector>, greater>> q; + dist[1] = 0; + q.push(make_pair(0, 1)); + while (!q.empty()) { + auto t = q.top(); + q.pop(); + if (vis[t.second]) continue; + for (auto i : g[t.second]) { + if (dist[i.first] > t.first + i.second) { + dist[i.first] = t.first + i.second; + q.push(make_pair(dist[i.first], i.first)); + } + } + vis[t.second] = true; + } +} + +int main() { + cin >> f >> p >> c >> m; + for (int i = 1; i <= p; i++) { + cin >> u >> v >> w; + g[u].push_back(make_pair(v, w)); + g[v].push_back(make_pair(u, w)); + } + dijkstra(); + for (int i = 1; i <= c; i++) { + cin >> x; + if (dist[x] <= m) ans.push(i); + } + cout << ans.size() << endl; + while (!ans.empty()) { + cout << ans.top() << endl; + ans.pop(); + } + return 0; +}