A 最少需要多少钱使得转账后 B 收到 100 元
100 = d(A) * W1 * W2 * … Wn
要让 A的值最小 则 (W1 * W2 * … Wn)
最大
#include<iostream>
#include<cstring>
using namespace std;
const int N = 2010, INF = 0x3f3f3f3f;
int n, m, start, ed;
double g[N][N], d[N];
bool st[N];
void dj() {
memset(d, 0x3f, sizeof d);
d[start] = 1;
for (int i = 0; i < n; i++) {
int t = -1;
for (int j = 1; j <= n; j++) {
if (!st[j] && (t == -1 || d[j] > d[t]))
t = j;
}
st[t] = true;
for (int j = 1; j <= n; j++) {
d[j] = max(d[j], d[t] * g[t][j]);
}
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
double z = (100.0 - c) / 100;
g[a][b] = g[b][a] = max(g[a][b], z);
}
cin >> start >> ed;
dj();
printf("%.8lf", 100 / d[ed]);
}
代码有大问题,过不掉,这题非常特殊,考虑边权的时候我们要的较大的值,所以dijkstra函数中把dist数组初始化为无穷大是错误的