Walk the single chain of hourly rides from home to the office, adding each wait, ride time, and geometric checkpoint delay for the expected arrival time.
Easy3ProbabilitySimulationMathInterviewNo attempts yetTime limit5sMemory limit512 MBYeongsu starts his first job next week. Public transport in Seoul is dense, but every vehicle now has to pass a police checkpoint. To avoid being late on his first day, Yeongsu collected the timetable and the expected delay of every ride on the way to the office. Find the expected time at which he reaches the office.
One ride behaves like this.
A ride with P=100 never passes the check, so it never reaches its destination stop.
Yeongsu leaves home at time 0, and at every stop he takes the ride that minimizes the expected arrival time.
The first line has the number of test cases T.
The first line of each test case has four integers N, M, H, O separated by spaces. N is the number of stops, M is the number of rides, H is the stop where his home is, and O is the stop where the office is.
Each of the next M lines has six integers Ai, Bi, Si, Ri, Di, Pi for one ride. Ai is the origin stop, Bi is the destination stop, Si is the minute of each hour at which the ride departs, Ri is the travel time, Di is the length of one delay, and Pi is the probability that a check finds a problem. Pi is a percentage.
For each test case print one line in the form Case #x: y, where x is the test case number starting at 1.
If Yeongsu can reach the office, y is the expected arrival time rounded to seven digits after the decimal point, with all seven digits printed, so an expectation that is exactly an integer still carries seven zeros after the point. If he cannot reach the office, print -1 in place of y, with no decimal point. When H=O the expectation is 0, so print 0.0000000.