You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
58 lines
1.2 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 2010;
|
|
const int M = 2e5 + 10;
|
|
|
|
typedef pair<double, int> PDI; // 堆中数值是浮点数,注意区别
|
|
|
|
int n, m;
|
|
double dis[N];
|
|
bool st[N];
|
|
|
|
int h[N], e[M], ne[M], idx;
|
|
double w[M]; // 边权为浮点数,与一般的题目有区别
|
|
void add(int a, int b, double c) {
|
|
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
|
|
}
|
|
int S, T;
|
|
void dijkstra() {
|
|
priority_queue<PDI> q; // 大顶堆
|
|
dis[S] = 1;
|
|
q.push({1, S});
|
|
|
|
while (q.size()) {
|
|
auto t = q.top();
|
|
q.pop();
|
|
int u = t.second;
|
|
if (st[u]) continue;
|
|
st[u] = true;
|
|
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
int v = e[i];
|
|
double a = 1 - w[i];
|
|
if (dis[v] < dis[u] * a) {
|
|
dis[v] = dis[u] * a;
|
|
q.push({dis[v], v});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
memset(h, -1, sizeof h);
|
|
cin >> n >> m;
|
|
|
|
while (m--) {
|
|
int a, b, c;
|
|
cin >> a >> b >> c;
|
|
double w = c * 0.01;
|
|
add(a, b, w), add(b, a, w);
|
|
}
|
|
|
|
cin >> S >> T;
|
|
|
|
dijkstra();
|
|
printf("%.8lf\n", 100 / dis[T]);
|
|
return 0;
|
|
} |