Commute War (Large)
Time limit5sMemory limit512 MB
Choose connecting services to minimize expected travel time when departures leave hourly and each ride faces repeated random inspection delays.
- Level
Hard8 of 10
- Topics
- Shortest path, Probability, Dynamic programming
- Solved
- No attempts yet
Problem
Yeongsu 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 through . Service runs like this.
- It leaves its origin junction at minute of every hour, that is at times , , , ..., where time is measured in minutes.
- The ride to its destination junction takes minutes.
- The police inspect the vehicle during the ride. The inspection itself takes no time, but with probability % something is wrong and the vehicle is delayed by minutes. When the delay ends the same inspection happens again, and again it delays the vehicle by minutes with probability %. The inspection repeats without limit until it passes. If the delay happens times, the ride takes minutes from departure to arrival.
- Once Yeongsu boards, he cannot get off before the destination junction.
A service with never passes the inspection, so it never reaches its destination junction.
Yeongsu is at junction , where his home is, at time , and the office is at junction . 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 .
Input
The first line has the number of test cases . 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. is the number of junctions, is the number of services, is the junction of the home, and is the junction of the office. Each of the next lines describes one service with six integers, in order: the origin junction , the destination junction , the departure minute , the ride time , the delay , and the delay probability given as a percentage.
Limits
- for every
- or for every pair with
Output
For each test case, print one line of the form Case #x: y. is the test case number starting from , and 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 , with no decimal point.