From 8f20be70f9f33e11417518bf4a3b539c24212331 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 20 Jul 2021 20:13:03 +0800 Subject: [PATCH] =?UTF-8?q?P1576=20=E6=9C=80=E5=B0=8F=E8=8A=B1=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R53723001 --- Luogu/problem/P1576/P1576.cpp | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Luogu/problem/P1576/P1576.cpp diff --git a/Luogu/problem/P1576/P1576.cpp b/Luogu/problem/P1576/P1576.cpp new file mode 100644 index 00000000..37ff8e74 --- /dev/null +++ b/Luogu/problem/P1576/P1576.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +int n, m, x, y, a, b; +long double z, dist[2005], g[2005][2005]; +bool st[2005]; + +void dijkstra() { + for (int i = 1; i <= n; i++) { + dist[i] = g[a][i]; + } + dist[a] = 1; + st[a] = true; + for (int i = 1; i < n; i++) { + int t = -1; + for (int j = 1; j <= n; j++) { + if (!st[j] && (t == -1 || dist[t] < dist[j])) { + t = j; + } + } + st[t] = true; + for (int j = 1; j <= n; j++) { + dist[j] = max(dist[j], dist[t] * g[t][j]); + } + } +} + +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> x >> y >> z; + g[x][y] = g[y][x] = (100 - z) / 100.00; + } + cin >> a >> b; + dijkstra(); + cout << fixed << setprecision(8) << 100 / dist[b] << endl; + return 0; +}