/*
假设给到B手上100时,A最少花费
从终点B倒推 到A的最小距离
B→C dist[C] * (100-w[i])/100 = 100(dist[B])
dist[C] = 100(dist[B])*100/(100-w[i])
I→J dist[J] * (100-w[i])/100 = dist[I]
dist[J] = dist[I]*100/(100-w[i])
*/
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=2010,M=2000010;
int h[N],ne[M],e[M],w[M],idx;
double dist[N];
int n,m,s,t;
bool st[N];
void add(int a,int b,int c)
{
e[idx] = b,w[idx]=c,ne[idx] = h[a],h[a]=idx++;
}
double spfa()
{
memset(dist,0x7f,sizeof dist);//注意double初始化0x3f = 0.0004767
dist[t] = 100;
queue<int> q;
q.push(t);
st[t]=true;
while(q.size())
{
int ver = q.front();
q.pop();
st[ver] = false;
for(int i=h[ver];i!=-1;i=ne[i])
{
int j=e[i];
if(dist[j]>dist[ver]*100/(100.0-w[i]))
{
dist[j]=dist[ver]*100/(100.0-w[i]);
if(!st[j])
{
st[j]=true;
q.push(j);
}
}
}
}
return dist[s];//我们最终结果在dist[s]上
}
dijkstra+堆优化
double dijkstra()
{
memset(dist,0x7f,sizeof dist);
priority_queue<PII,vector<PII>,greater<PII>> heap;
heap.push({100.0,t});
while(heap.size())
{
auto u = heap.top();
heap.pop();
double d = u.first;//dist[ver]
int ver = u.second;
//顺序又错了 在遍历j之前判断ver 而不是判断j
if(st[ver]) continue;
st[ver]=true;
for(int i=h[ver];i!=-1;i=ne[i])
{
int j=e[i];
if(dist[j]>d*100/(100.0-w[i]))
{
dist[j]=d*100/(100.0-w[i]);
heap.push({dist[j],j});
}
}
}
return dist[s];
}
int main()
{
memset(h,-1,sizeof h);
cin >> n >> m;
for(int i=0;i<m;i++)
{
int a,b,c;
cin >> a >> b >> c;
add(a,b,c),add(b,a,c);
}
cin >> s >> t;
printf("%.8lf\n",spfa());
//printf("%.8lf\n",dijkstra());
return 0;
}