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.
Input
6 8 1 0 0.02478 3 4 0.49787 3 1 0.00335 0 5 0.06737 0 2 0.76787 5 1 0.00045 4 1 0.93533 2 3 0.18315 3 5 2 1 0 1 1 1 0 1 0 0 0 3 4 2 0 0.75008 0 2 0.00004 0 1 0.01831 1 2 0.00091 0 2
Output
0.00078 impossible 1.00000 0.00004