1

网恋被骗五毛  •  1年前


include <bits/stdc++.h>

using namespace std; typedef pair<double, int>PII; const int N = 1e7 + 5; int e[N], ne[N], h[N]; int n, m, idx, A, B, t; double dist[N], w[N]; bool st[N];

void add(int x, int y, double z) {

w[idx] = z, e[idx] = y, ne[idx] = h[x], h[x] = idx++;

}

void dijkstra(int A) {

for (int i = 1; i <= n; i++)
	dist[i] = -1e9;
dist[A] = 1;
priority_queue<PII>heap;
heap.push({1, A});
while (heap.size()) {
	auto t = heap.top();
	heap.pop();
	int ver = t.second;
	double 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] < distance * w[i]) {
			dist[j] = distance * w[i];
			heap.push({dist[j], j});
		}
	}
}

}

int main() {

cin >> n >> m;
memset(h, -1, sizeof h);
int a, b, c;
for (int i = 1; i <= m; i++) {
	cin >> a >> b >> c;
	add(a, b, 1.0 - c / 100.0);
//	cout << 1.0 - c / 100.0 << endl;
	add(b, a, 1.0 - c / 100.0);
}
cin >> A >> B;
dijkstra(A);
printf("%.8lf", 100 / dist[B]);

}


评论:

请先登录,才能进行评论