Bancopia

Time limit1sMemory limit128 MB

Summary
Place up to m police posts, each halving one road's robbery probability, so that the safest a-to-b route has the smallest possible robbery probability.
Level

Hard8 of 10

Topics
Graph, Shortest path, Dynamic programming, Brute force
Solved
No attempts yet

Problem

Gold transports in Bancopia are risky because of frequent robberies, and some roads are more dangerous than others. To move gold safely between two cities, the Bancopians want to place police posts on some roads to make them safer.

You are given the cities of Bancopia, the roads between them, and the two cities the gold transport travels between. Each road has a robbery probability: given that a gold transport uses that road, this is the probability that a robbery happens on that road. Robberies on different roads are independent.

You are also given the maximum number of police posts you may place. At most one police post can be placed on each road, and a police post exactly halves the robbery probability of that road.

The transport always takes the safest route between the two cities: the route with the smallest overall robbery probability. If a route uses roads with (possibly halved) robbery probabilities p1,p2,…,pkp_1, p_2, \dots, p_k, its overall robbery probability is 1−∏i=1k(1−pi)1 - \prod_{i=1}^{k}(1 - p_i).

Place the police posts so that the robbery probability of the safest route is as small as possible, and report that minimum probability.

Input

The first line contains a single integer TT: the number of test cases. Each test case has the following format:

  • One line with five integers nn, ww, mm, aa, bb separated by spaces, where 2≤n≤1002 \le n \le 100 is the number of cities, 1≤w≤1041 \le w \le 10^4 is the number of roads, 1≤m≤1001 \le m \le 100 is the maximum number of police posts, and aa and bb are the two cities between which the transport travels. Cities are numbered with distinct integers from {1,…,n}\{1, \dots, n\}.
  • ww lines, each describing one road with three values s1s_1, s2s_2, pp separated by spaces, where s1s_1 and s2s_2 are the cities the road connects (s1≠s2s_1 \ne s_2, 1≤s1,s2≤n1 \le s_1, s_2 \le n) and 0≤p≤10 \le p \le 1 is the robbery probability of that road.

No two roads connect the same pair of cities. Every road is bidirectional, and its robbery probability is the same in both directions. It is guaranteed that at least one route from aa to bb exists.

Output

For each test case, print a single line containing one number: the robbery probability of the safest route from aa to bb when at most mm police posts are placed to minimize this probability, rounded to four digits after the decimal point. Rounding is done the usual way (round half up): 0.12345…0.12345\ldots becomes 0.12350.1235 and 0.12344…0.12344\ldots becomes 0.12340.1234.

Figure 1: The maps illustrate one scenario. The left map shows the safest route without police posts; the right map shows the safest route after the posts are placed. Cities are numbered and each road is labelled with its robbery probability. Next to the destination city, the robbery probability of the entire route is shown.

Examples3

  1. Example 1

    Input
    1
    6 8 2 1 6
    1 2 0.1
    1 3 0.15
    2 3 0.05
    2 4 0.1
    3 5 0.05
    4 5 0.15
    4 6 0.2
    5 6 0.02
    
    Expected output
    0.1162
    
  2. Example 2

    Input
    1
    2 1 1 1 2
    1 2 0.4
    
    Expected output
    0.2000
    
  3. Example 3

    Input
    1
    3 3 1 1 3
    1 3 0.5
    1 2 0.1
    2 3 0.1
    
    Expected output
    0.1450