Ski
Time limit1sMemory limit1024 MB
Given a DAG of ski paths with distances and speeds, find the route from any lift-reachable point to Hotel IOI minimizing the total time divided by total distance.
- Level
Medium6 of 10
- Topics
- Graph, Dynamic programming, Binary search, Greedy
- Solved
- No attempts yet
Problem
JOI runs Hotel IOI on the IOI Plateau, a place famous for its ski resort. The IOI Plateau has very complex terrain, which makes it popular with advanced skiers, but that same terrain makes it far from friendly to beginners. JOI wants beginners to appreciate what the IOI Plateau has to offer.
So he plans to find the easiest course and use it to advertise the IOI Plateau to beginners. The easiest course is the one with the lowest average speed (the speed obtained by dividing the total distance of the course by the time it takes). Because JOI wants people to stay at Hotel IOI, the start of the course must be a point reachable by a lift leaving Hotel IOI directly, and the end of the course must be Hotel IOI.
Each point on the IOI Plateau is assigned a smaller number the higher its elevation. No two points have the same elevation, and one can only move from a higher point to a lower point, so it is impossible to return from a point to the same point.
Given the paths usable as courses together with their distances and average speeds for those segments, and given the points reachable from Hotel IOI by lift, write a program that finds the average speed of the easiest course and prints the integer obtained by rounding that average speed to the nearest whole number, with the first decimal place rounded.
Input
The first line contains three positive integers separated by spaces: n (1 ≤ n ≤ 10000), the largest point number and the point representing Hotel IOI; m (1 ≤ m < n), the number of points reachable from Hotel IOI by lift; and c (1 ≤ c ≤ 100000), the number of paths usable as courses.
The second line contains m positive integers ai (1 ≤ i ≤ m, 1 ≤ ai < n) separated by spaces, representing the points reachable from Hotel IOI by lift.
Each of the c lines from the third line through the (j + 2)-th line (1 ≤ j ≤ c) contains four positive integers separated by spaces: fj, the point number of the start of a path usable as a course; tj (1 ≤ fj < tj ≤ n), the point number of its end; dj (1 ≤ dj ≤ 100), the length of the path from its start to its end; and sj (1 ≤ sj ≤ 100000), the average speed obtained when traveling that path.
For every input used in grading, rounding to the first decimal place any value within 0.01 of the average speed of the easiest course yields the same integer. Also, for every input used in grading, there exists a course whose start is a point reachable by a lift leaving Hotel IOI directly and whose end is Hotel IOI.
Output
Write the output to standard output. Print as an integer the average speed of the easiest course, rounded to the nearest whole number at the first decimal place.