From 951177b1710be082742839b1ddb5116dde3cede7 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 23 Jul 2021 20:01:57 +0800 Subject: [PATCH] P1339 [USACO09OCT]Heat Wave G R54021228 --- Luogu/problem/P1339/P1339.cpp | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Luogu/problem/P1339/P1339.cpp diff --git a/Luogu/problem/P1339/P1339.cpp b/Luogu/problem/P1339/P1339.cpp new file mode 100644 index 00000000..78f9f9ff --- /dev/null +++ b/Luogu/problem/P1339/P1339.cpp @@ -0,0 +1,38 @@ +#include + +using namespace std; + +int n, m, s, t, u, v, w, dist[2505]; +vector> g[2505]; +bool st[2505]; + +void dijkstra() { + memset(dist, 0x3f, sizeof(dist)); + dist[s] = 0; + priority_queue, vector>, greater>> q; + q.push(make_pair(0, s)); + while (!q.empty()) { + auto t = q.top(); + q.pop(); + if (st[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)); + } + } + st[t.second] = true; + } +} + +int main() { + cin >> n >> m >> s >> t; + for (int i = 1; i <= m; i++) { + cin >> u >> v >> w; + g[u].push_back(make_pair(v, w)); + g[v].push_back(make_pair(u, w)); + } + dijkstra(); + cout << dist[t] << endl; + return 0; +}