From 9617b48f6f888b1c56c45d83a77692876d593b97 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 23 Sep 2021 20:45:54 +0800 Subject: [PATCH] =?UTF-8?q?1126.=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 https://www.acwing.com/problem/content/submission/code_detail/7875736/ --- AcWing/1126/1126.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 AcWing/1126/1126.cpp diff --git a/AcWing/1126/1126.cpp b/AcWing/1126/1126.cpp new file mode 100644 index 00000000..37ff8e74 --- /dev/null +++ b/AcWing/1126/1126.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; +}