#include <bits/stdc++.h>

using namespace std;

typedef pair<double, int> PII;
const int N = 2010;

int n, m;
int h[N], e[N], ne[N], idx;
double w[N];
double dist[N];
bool st[N];
int A,B;
void add(int a, int b, double c)
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

double dijkstra(int x,int y)
{
    for(int i=0;i<N;i++){
    	dist[i]=nextafter(1.0, 0.0);
	}
    dist[x] = 1.0;
    priority_queue<PII, vector<PII>, greater<PII>> heap; 
    heap.push({1.0, x});

    while (heap.size())
    {
        auto t = heap.top();
        heap.pop();

        int ver = t.second, distance = t.first;

        if (st[ver]) continue;
        st[ver] = true;

        for (int i = h[ver]; i != -1; i = ne[i])
        {
            int j = e[i];
            if (dist[j] < dist[ver] * w[i])
            {
                dist[j] = dist[ver] * w[i];
                heap.push({dist[j], j});
            }
        }
    }
    return dist[y];
}
int main(){
	cin >> n >> m;
	memset(h, -1, sizeof h);
	while (m -- )
    {
        int a, b, c;
        cin >> a >> b >> c;
        int wc=1-double(c)/100;
        add(a, b, wc);
        add(b, a, wc);
    }
    cin >> A >> B;
    double ll=dijkstra(A,B);
    long double result=100/ll;
    printf("%.8lf",result);
	return 0;
}

0 comments

No comments so far...