1126. 最小花费
作者:
闪回
,
2024-04-01 16:08:47
,
所有人可见
,
阅读 2
保留最大边,并且更新用乘号
#include<bits/stdc++.h>
using namespace std;
const int N = 2010,M = 1e5+10;
bool st[N];
double dist[N];
double g[N][N];
int n,m,s,t;
void dijkstra()
{
//memset(dist,0x3f,sizeof dist);
dist[s] = 1;
for(int i = 1;i<=n;i++)
{
int t = -1;
for(int j = 1;j<=n;j++)
if(!st[j] && (t == -1 || dist[j] > dist[t]))
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;
while(m--)
{
int x,y,z;
cin>>x>>y>>z;
double temp = (100.0-z) / 100;
g[x][y] = g[y][x] = max(g[x][y],temp);
}
cin>>s>>t;
dijkstra();
printf("%.8lf",100/dist[t]);
return 0;
}