Competitions are not in fashion anymore. What is fashionable now are cooperative games, where the participants collaborate to achieve a common goal. So, friends get inspired by the chain game, in which an array of people whisper a message in order from one extreme to the other one, trying that gets not corrupted on the way. But, to make the game more fun, some changes are made:
Let be the initial transmitter of , and let be the final receiver. At each step of the game, the person that just got (or , if it is the first round) must choose another person and transmit to him or her. For every pair , we know the probability that the direct transmision of the message from to is correct. That probability is independent of the round. A corrupted message never gets recovered. The game ends when reaches .
Playing optimally, what is the probability that gets correctly transmitted from to ?
Input consists of several cases. Every case begins with the number of friends and the number of probabilities that are strictly positive. Follow triplets , , , where . Finally, we have and . Assume , , and that every pair of and appears at most once in the input. Friends are numbered between and .
For every case, print with five digits after the decimal point the maximum probability that the message correctly reaches from . If it is impossible, tell so.
The expected solution is based upon a fundamental graph algorithm.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T11:48:31.102Z
© Jutge.org, 2006–2026.
https://jutge.org