Problem
Traveler Kim Soon-rye is exploring the Kingdom of NodeCrew. The kingdom has n cities and m buses. Each of the m buses operates between two distinct cities, traveling back and forth.
The positions of the cities are given in terms of their distances from Kim Soon-rye's starting location in the x direction (+x: east / -x: west) and the y direction (+y: north / -y: south), measured in meters.
Kim Soon-rye can travel between cities using buses or by walking. Write a function solution that calculates the estimated shortest time (in minutes) it will take for Kim Soon-rye to reach her destination city. The function should return the time truncated to three decimal places.
Assumptions for Kim Soon-rye’s journey include:
- Kim Soon-rye walks at a speed of 100 meters per minute.
- Buses do not allow boarding or alighting mid-journey; they only stop at their starting and ending cities.
- The distance between two cities separated by
xin the east-west direction andyin the north-south direction is . - There is no waiting time for boarding a bus.
Constraints
-
citiescontains information forncities, numbered from1ton:- Each element of
citiesis composed of the'xdistance and'ydistance from Kim Soon-rye's starting position. - The number of cities
nis a natural number between 2 and 1,000 inclusive. xandyare real numbers between -10,000 and 10,000 (meters), given to three decimal places.
- Each element of
-
busescontains information formbuses:- Each bus connects two cities and is described by the starting city number (
s), the destination city number (e), and the travel time (time, in minutes) between the two cities. sandeare natural numbers between 1 andninclusive.mis a natural number up to 50,000 inclusive.timeis a natural number up to 1,000 inclusive.
- Each bus connects two cities and is described by the starting city number (
-
destrepresents the city number Kim Soon-rye wishes to reach.
Test Case
| Test Case Number | cities | buses | dest | answer |
|---|---|---|---|---|
| 1 | [[-5.457,-13.456],[93.551,-98.776],[92.740,87.973],[89.438,87.416]] | [[1,3,1],[4,1,1]] | 3 | 1.145 |
| 2 | [[-0.635,97.175],[71.424,97.484],[-54.368,-85.041],[48.631,89.916],[-93.897,38.331]] | [[1,4,1],[2,3,1],[3,4,1]] | 4 | 1.022 |
Explanation for Test Case 1
- Walking to city 1 takes 0.145 minutes. From city 1, taking a bus to city 3 takes 1 minute. Thus, the total time to reach city 3 is 1.145 minutes.
Explanation for Test Case 2
- Walking directly to city 4 from the starting point takes 1.022 minutes. This is the fastest route.