n relays numbered 0 to n - 1. The list links describes two-way connections: links[i] = [a, b] joins relays a and b, and chances[i] is the probability that a message crosses that link intact. Failures on different links are independent, so the chance of getting through a whole route is the product of its links' chances.
Return the highest chance of delivering a message from relay source to relay target. If no route connects them, return 0.
An answer within 10⁻⁵ of the correct one is accepted.n=4, links=[[0, 1], [1, 3], [0, 2], [2, 3]], chances=[0.9, 0.5, 0.6, 0.8], source=0, target=3 → 0.48
Through node 1 the message gets through with chance 0.9 · 0.5 = 0.45, through node 2 with 0.6 · 0.8 = 0.48. The second route wins.
n=3, links=[[0, 1]], chances=[1.0], source=0, target=2 → 0
No link reaches node 2 at all, so the chance is 0.
n=3, links=[[0, 1], [1, 2], [0, 2]], chances=[0.7, 0.7, 0.4], source=2, target=0 → 0.48999999999999994
n=4, links=[[0, 1], [1, 3], [0, 2], [2, 3]], chances=[0.9, 0.5, 0.6, 0.8], source=0, target=3
0.48
Run checks the first 3 tests in your browser. Submit checks all 63 tests on the server, hidden ones included.