Fare Dodging
Time limit1sMemory limit128 MB
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 won plus won per kilometer of the shortest distance between A and B, that is won, where 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 won plus 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 . ()
Each test case is laid out as follows.
-
The first line has 7 integers separated by spaces.
- (): the number of cities on the train network
- (): the number of tracks that directly join two cities
- (): the source
- (, ): the destination
- (): the base fare of a ticket
- (): the per kilometer amount added to a ticket and to a fine
- (): the base fine for fare dodging
-
Each of the next lines describes one track with 4 integers separated by spaces. Every track is bidirectional. Line holds the following.
- (): the city at one end of track
- (): the city at the other end of track
- (): the probability that a ticket is checked on the train running track , given as a percentage
- (): the length of track in kilometers
For every pair with , , 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 and the expected cost on route Y is , then the expected cost of X followed by Y is .
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 (), from city 2 to city 3 ride for free (the expected fine there is won), and from city 3 to city 4 buy another ticket for 20 won (). That commute has an expected cost of won, and nothing beats it.