From 5860aae05150cb95b9a7e8990890b92eccb87ffd Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 24 Mar 2022 21:51:04 +0800 Subject: [PATCH] =?UTF-8?q?P1807=20=E6=9C=80=E9=95=BF=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R72243775 --- Luogu/P1807/P1807.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Luogu/P1807/P1807.cpp diff --git a/Luogu/P1807/P1807.cpp b/Luogu/P1807/P1807.cpp new file mode 100644 index 00000000..924c5219 --- /dev/null +++ b/Luogu/P1807/P1807.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1505, + INF = 0x3f3f3f3f; + +int n, m, dist[N]; +std::vector> g[N]; + +void spfa() { + memset(dist, 0xff, sizeof(dist)); + + std::queue q; + q.push(1); + dist[1] = 0; + + while (!q.empty()) { + int u = q.front(); + q.pop(); + + for (auto e : g[u]) { + int v = e.first, + w = e.second; + + if (dist[v] < dist[u] + w) { + dist[v] = dist[u] + w; + q.push(v); + } + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin >> n >> m; + for (int i = 1; i <= m; i++) { + int u, v, w; + cin >> u >> v >> w; + g[u].push_back(std::make_pair(v, w)); + } + spfa(); + cout << dist[n] << endl; + return 0; +}