Choose connecting services to minimize expected travel time when departures leave hourly and each ride faces repeated random inspection delays.
Hard8Shortest pathProbabilityDynamic programmingNo attempts yetTime limit5sMemory limit512 MBYeongsu starts his first job next week. Seoul has dense public transit, but for some reason the police now inspect every service. To avoid being late, Yeongsu collected the timetable and the expected delay of every service along the junctions between his home and the office. Find the expected time it takes him to reach the office.
The junctions are numbered 0 through N−1. Service i runs like this.
A service with Pi=100 never passes the inspection, so it never reaches its destination junction.
Yeongsu is at junction H, where his home is, at time 0, and the office is at junction O. If he is at a junction exactly at the departure time of a service leaving that junction, he boards it without waiting. Every time he reaches a junction he knows the current time, and he takes the service that minimizes the expected remaining time. If the home and the office are the same junction, the time is 0.
The first line has the number of test cases T. Each test case has the following form.
N M H O
A[0] B[0] S[0] R[0] D[0] P[0]
...
A[M-1] B[M-1] S[M-1] R[M-1] D[M-1] P[M-1]
The first line of a test case has four integers. N is the number of junctions, M is the number of services, H is the junction of the home, and O is the junction of the office. Each of the next M lines describes one service with six integers, in order: the origin junction Ai, the destination junction Bi, the departure minute Si, the ride time Ri, the delay Di, and the delay probability Pi given as a percentage.
For each test case, print one line of the form Case #x: y. x is the test case number starting from 1, and y is the expected time to reach the office, rounded to seven decimal places. Always print seven digits after the decimal point. If the office cannot be reached, print -1 in place of y, with no decimal point.