Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code it using Python Where to position fire engines Some roads in the city are prone to flooding. In severe flooding some of these

Please code it using Pythonimage text in transcribedimage text in transcribed

Where to position fire engines Some roads in the city are prone to flooding. In severe flooding some of these roads may not be usable even by fire trucks. This can potentially make some areas of the city inaccessible to the service. When heavy rain is forecasted, the fire department wants to position fire trucks around the city in a way that even if all the flood-prone roads are closed, every area is reachable by at least one fire truck. Your job is to write a function possible_locations (safe_map) that takes a map of the city containing only "safe" roads (those that are not affected by flooding) and produces a list indicating the minimum number of fire trucks required and possible locations at which a firetruck must be positioned 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 of input is string. The first line starts with the character 'U' followed by space, followed by a natural number n specifying the number of areas. The remaining lines (if any) are of the form a b which means that area a is directly connected to area b via a safe two-way road. Note that, the data string will contain either a b or b a (not both) The function must return a list. The order of elements in the list does not matter. The number of elements in the list must be equal to the minimum number of fire trucks needed to service everywhere in the city even if all the flood-prone roads are closed. Note that flood-prone roads are not included in the map.] Each element of the list is a set of areas so that if there is one fire truck in one of the areas in the set, all the areas in the set can be reached For example Test Result safe_map U 2 0 1 [ [0, 111 print(sorted (sorted (areas) for areas in possible_locations (safe_map))) safe-map = " \ U 2 Where to position fire engines Some roads in the city are prone to flooding. In severe flooding some of these roads may not be usable even by fire trucks. This can potentially make some areas of the city inaccessible to the service. When heavy rain is forecasted, the fire department wants to position fire trucks around the city in a way that even if all the flood-prone roads are closed, every area is reachable by at least one fire truck. Your job is to write a function possible_locations (safe_map) that takes a map of the city containing only "safe" roads (those that are not affected by flooding) and produces a list indicating the minimum number of fire trucks required and possible locations at which a firetruck must be positioned 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 of input is string. The first line starts with the character 'U' followed by space, followed by a natural number n specifying the number of areas. The remaining lines (if any) are of the form a b which means that area a is directly connected to area b via a safe two-way road. Note that, the data string will contain either a b or b a (not both) The function must return a list. The order of elements in the list does not matter. The number of elements in the list must be equal to the minimum number of fire trucks needed to service everywhere in the city even if all the flood-prone roads are closed. Note that flood-prone roads are not included in the map.] Each element of the list is a set of areas so that if there is one fire truck in one of the areas in the set, all the areas in the set can be reached For example Test Result safe_map U 2 0 1 [ [0, 111 print(sorted (sorted (areas) for areas in possible_locations (safe_map))) safe-map = " \ U 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

explain what is meant by the terms unitarism and pluralism

Answered: 1 week ago