#K47152. Shortest Travel Time
Shortest Travel Time
Shortest Travel Time
You are given a set of cities and road segments connecting these cities. Each segment provides a distance and a speed limit. Your task is to compute the shortest travel time from a given starting city to a destination city using the formula:
\(t = \frac{d}{s}\)
If there is no valid route between the cities, output -1. The answer must be rounded to two decimal places. This problem can be efficiently solved using Dijkstra's algorithm.
inputFormat
The input consists of multiple datasets. Each dataset is formatted as follows:
- The first line contains an integer \(C\) representing the number of cities. If \(C = 0\), it indicates the end of input.
- The next \(C\) lines each contain a city name.
- The following line contains an integer \(S\) representing the number of road segments.
- Each of the next \(S\) lines describes a road segment in the format: City1 City2 Distance Speed, where Distance and Speed are integers. The travel time for a segment is computed as \(t = \frac{d}{s}\).
- The last line for the dataset contains two city names separated by a space: the start city and the destination city.
For each dataset, compute the shortest travel time from the start to the destination. The output for each dataset should appear on a separate line.
outputFormat
For each dataset, output a single line with the shortest travel time rounded to two decimal places if a route exists, or -1 if no route exists.
## sample3
CityA
CityB
CityC
3
CityA CityB 100 100
CityB CityC 100 100
CityA CityC 300 150
CityA CityC
2
CityA
CityB
2
CityA CityB 300 150
CityB CityA 300 150
CityA CityB
0
2.00
2.00
</p>