#P1266. Fastest Route in a City
Fastest Route in a City
Fastest Route in a City
In today's busy society, we often choose the fastest route rather than the shortest one. When driving, the speed limit on each road is the critical factor as your car cannot exceed the current speed limit. Unfortunately, some speed limit signs are missing, so you are not able to determine the posted speed. A justifiable solution is to drive at the road's original speed.
You are given a modern city's road network which consists only of intersections and roads. Each road is directed and connects exactly two intersections. At the start of each road there may be at most one speed limit sign. For a road, if the posted speed limit is available (i.e. not -1), you must obey it; otherwise, you drive at the road's original speed. More formally, for each road, the effective speed is defined as:
$v = \begin{cases} p, & \text{if } p \neq -1 \\ r, & \text{if } p = -1 \end{cases}$
and the time taken to travel the road is computed as $T=\frac{d}{v}$, where $d$ is the distance of the road.
Given two intersections $A$ and $B$, your task is to compute the minimum travel time from $A$ to $B$. You may assume that acceleration is instantaneous and there are no traffic delays. If there is no route from $A$ to $B$, output unreachable
.
inputFormat
The first line of input contains four integers: n m A B
, where:
n
is the number of intersections (numbered from 1 to n).m
is the number of roads.A
andB
are the starting and destination intersections respectively.
The following m
lines each contain five integers: u v d r p
, describing a directed road from intersection u
to intersection v
with a distance d
, an original speed limit r
, and a posted speed limit p
. If p
is -1
, then the speed limit sign is missing and the road should be traversed at the original speed r
.
There is at most one road from any intersection A to B.
outputFormat
If there is a route from A
to B
, output the minimum travel time with exactly 6 decimal places. Otherwise, output unreachable
.
sample
3 3 1 3
1 2 100 50 70
2 3 150 70 -1
1 3 300 60 80
3.571429