Cooperative game P74845


Statement
 

pdf   zip

Competitions are not in fashion anymore. What is fashionable now are cooperative games, where the participants collaborate to achieve a common goal. So, nn friends get inspired by the chain game, in which an array of people whisper a message MM in order from one extreme to the other one, trying that MM gets not corrupted on the way. But, to make the game more fun, some changes are made:

Let xx be the initial transmitter of MM, and let yy be the final receiver. At each step of the game, the person uu that just got MM (or xx, if it is the first round) must choose another person vv and transmit MM to him or her. For every pair (u,v)(u, v), we know the probability puvp_{uv} that the direct transmision of the message from uu to vv is correct. That probability is independent of the round. A corrupted message never gets recovered. The game ends when MM reaches yy.

Playing optimally, what is the probability that MM gets correctly transmitted from xx to yy?

Input

Input consists of several cases. Every case begins with the number of friends nn and the number of probabilities puvp_{uv} that are strictly positive. Follow mm triplets uu, vv, puvp_{uv}, where uvu \ne v. Finally, we have xx and yy. Assume 1n1041 \le n \le 10^4, 0m5n0 \le m \le 5n, and that every pair of uu and vv appears at most once in the input. Friends are numbered between 00 and n1n-1.

Output

For every case, print with five digits after the decimal point the maximum probability that the message correctly reaches yy from xx. If it is impossible, tell so.

Hint

The expected solution is based upon a fundamental graph algorithm.

Public test cases
  • 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
    
  • Information
    Author
    Enric Rodríguez
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++