Question: Please code using Python The longest path When it comes to emergencies, a path with the minimum travel distance is not as important as a

Please code using Python

Please code using Python The longest path When it comes to emergencies,

The longest path When it comes to emergencies, a path with the minimum travel distance is not as important as a path with the minimum travel time. Given the position of a fire truck, the fire department wants to know the path to an area in the city that takes the longest time to get to, assuming that the truck always takes a path that takes the shortest time Write a function longest_path(city_map, position) that takes a map of the city (described in terms of areas and the roads in between), and the position of a fire truck, and returns a path to an area that is reachable but takes the longest time to get to (assuming that the truck always takes the shortest-time path to any destination) Details of input and output The city consists of n areas, numbered 0 to n-1 and a number of roads. Each road connects two areas and all roads are two-way. The type city_map is string. The first line starts with the character'U' followed by space, followed by a natural number n specifying the number of areas, followed by the character W. The remaining lines (if any) are of the form a b t which means that the fire truck can move from area a to b (or b to a) in time t The parameter position is an integer in [0, 1, 2, ..., n-1) indicating the area in which the fire truck is positioned The function must return a path in the form of a list of integers. The first element is the current position of the truck. The remaining elements (if any) must be the areas through which the fire truck must travel to get to the destination (including the destination) For example: Test Result city-map """\ 0, 3, 2] = 0 25 0 3 2 3 2 2 True print (longest_path(city_map, 0)) print(longest_path(city_map, 1)) print(longest_path(city_map, 2)) print(longest_path(city_map, 3) in [[3, 0], [3, 2]]) The longest path When it comes to emergencies, a path with the minimum travel distance is not as important as a path with the minimum travel time. Given the position of a fire truck, the fire department wants to know the path to an area in the city that takes the longest time to get to, assuming that the truck always takes a path that takes the shortest time Write a function longest_path(city_map, position) that takes a map of the city (described in terms of areas and the roads in between), and the position of a fire truck, and returns a path to an area that is reachable but takes the longest time to get to (assuming that the truck always takes the shortest-time path to any destination) Details of input and output The city consists of n areas, numbered 0 to n-1 and a number of roads. Each road connects two areas and all roads are two-way. The type city_map is string. The first line starts with the character'U' followed by space, followed by a natural number n specifying the number of areas, followed by the character W. The remaining lines (if any) are of the form a b t which means that the fire truck can move from area a to b (or b to a) in time t The parameter position is an integer in [0, 1, 2, ..., n-1) indicating the area in which the fire truck is positioned The function must return a path in the form of a list of integers. The first element is the current position of the truck. The remaining elements (if any) must be the areas through which the fire truck must travel to get to the destination (including the destination) For example: Test Result city-map """\ 0, 3, 2] = 0 25 0 3 2 3 2 2 True print (longest_path(city_map, 0)) print(longest_path(city_map, 1)) print(longest_path(city_map, 2)) print(longest_path(city_map, 3) in [[3, 0], [3, 2]])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!