This page is still under construction.

Parts of this page are still being built. What you see may change.

Fare Dodging

Time limit1sMemory limit128 MB

Summary
A commuter mixes per-track tickets priced from shortest distances with free rides that risk expected fines to minimize the expected cost from start to end.
Level

Medium6 of 10

Topics
Shortest path, Graph, Probability
Solved
No attempts yet

Problem

Sanghyun is an agent of a secret organization, and he takes a train to work every morning. One day he noticed something unfair. He pays the fare every single day, yet a conductor almost never checks his ticket. Over several years he wrote down, for every track, how likely a check is on the train that runs it.

The fine for fare dodging is usually larger than the fare itself. Instead of skipping the fare everywhere, Sanghyun works out the fares, the fines and the check probabilities, then commutes the way that makes the expected cost as small as possible. On some legs buying a ticket is better, on others riding for free is better.

A ticket is bought for a source A and a destination B. It costs the base fare ss won plus pp won per kilometer of the shortest distance between A and B, that is s+p×dist(A,B)s + p \times \mathrm{dist}(A, B) won, where dist(A,B)\mathrm{dist}(A, B) is the shortest distance between the two cities. The ticket is valid only on trains that run the shortest route between A and B.

If a check happens on a train Sanghyun boarded without a ticket, he pays a fine. The fine is a base of yy won plus pp won per kilometer of the distance from the city the train visited last to the stop it is pulling into. A fare dodger normally has to leave the train at once, but Sanghyun is a secret agent and good at disguises. He pays the fine and stays on board.

Write a program that finds the commute from start to end with the smallest expected cost and reports that expected cost.

Input

The first line has the number of test cases TT. (T≤100T \le 100)

Each test case is laid out as follows.

  • The first line has 7 integers separated by spaces.

    1. nn (2≤n≤2002 \le n \le 200): the number of cities on the train network
    2. mm (1≤m≤n(n−1)/21 \le m \le n(n-1)/2): the number of tracks that directly join two cities
    3. start\mathrm{start} (1≤start≤n1 \le \mathrm{start} \le n): the source
    4. end\mathrm{end} (1≤end≤n1 \le \mathrm{end} \le n, start≠end\mathrm{start} \ne \mathrm{end}): the destination
    5. ss (1≤s≤10001 \le s \le 1000): the base fare of a ticket
    6. pp (1≤p≤10001 \le p \le 1000): the per kilometer amount added to a ticket and to a fine
    7. yy (s<y≤1000s < y \le 1000): the base fine for fare dodging
  • Each of the next mm lines describes one track with 4 integers separated by spaces. Every track is bidirectional. Line ii holds the following.

    1. aia_i (1≤ai≤n1 \le a_i \le n): the city at one end of track ii
    2. bib_i (ai<bi≤na_i < b_i \le n): the city at the other end of track ii
    3. cic_i (0≤ci≤1000 \le c_i \le 100): the probability that a ticket is checked on the train running track ii, given as a percentage
    4. did_i (1≤di≤10001 \le d_i \le 1000): the length of track ii in kilometers

For every pair with i≠ji \ne j, (ai,bi)≠(aj,bj)(a_i, b_i) \ne (a_j, b_j), so the same two cities are never joined twice. A route from start to end always exists.

Output

For each test case print, on its own line, the smallest expected cost of getting from start to end. Print two digits after the decimal point, and keep both digits even when they are zeros.

Every fare and every expected fine lands exactly on a multiple of 0.01 won, so no rounding is ever ambiguous.

Hint

The expected fine is the check probability times the fine. Checks on different tracks are independent, so if the expected cost on route X is E[X]E[X] and the expected cost on route Y is E[Y]E[Y], then the expected cost of X followed by Y is E[X]+E[Y]E[X] + E[Y].

In the third case of the public test, the best route from city 1 to city 4 is this. From city 1 to city 2 buy a ticket for 20 won (10+1×1010 + 1 \times 10), from city 2 to city 3 ride for free (the expected fine there is 0.1×(100+1×120)=220.1 \times (100 + 1 \times 120) = 22 won), and from city 3 to city 4 buy another ticket for 20 won (10+1×1010 + 1 \times 10). That commute has an expected cost of 20+22+20=6220 + 22 + 20 = 62 won, and nothing beats it.

Examples1

  1. Example 1

    Input
    3
    2 1 1 2 10 1 100
    1 2 20 50
    2 1 1 2 10 1 100
    1 2 60 50
    4 4 1 4 10 1 100
    1 4 50 90
    1 2 90 10
    2 3 10 120
    3 4 90 10
    
    Expected output
    30.00
    60.00
    62.00