1

Find a Route (Id-1533)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1533

 

Rahul is fond of travelling and he visits cities and towns in the country whenever possible. All cities in the country are not connected to each other. Given the details of the cities that are connected to each city, source city from where he begins the travel and the destination city of the travel, design an algorithm and write a C++ code to list down the cities in the travel. Rahul must not visit a city more than once. When the destination city name is in the connected cities of the current city, chose it and complete the route. When the destination city name is not in the list of connected cities to current city and there are more than one city from the current city, he sorts the city names and include the first minimum city name that is not yet visited. For example, if the connection between the cities are given as follows, source city as A and destination city as F the list of cities in the travel are A, B, D and F.

 

CityConnected Cities
AE, B
BD
CE,D
DF
EF

 

Use vectors, maps and algorithms such as sort, find in STL for implementation. Assume that the connection of cities is very simple and there is a path as described in the problem.

Input Format

Number of cities that are connected to other cities, ‘n’

Name of city1

Number of neighbouring cities for city1, ‘m’

First neighbouring city of city1

Second neighbouring city of city1

mth neighbouring city of city1

Name of cityn

Number of neighbouring cities for cityn, ‘m’

First neighbouring city of cityn

Second neighbouring city of cityn

mth neighbouring city of cityn

 

Output Format

Name of cities in the list

Code

Please Comment Working if the code worked to you

If you have other working codes please comment the codes enclosing with <pre> and </pre> 🙂

Example: <pre> Your Code </pre>

C++ Code 

The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

 

Click Here to Leave a Comment Below 1 comments
nandini - April 5, 2018

it says

Your program has exceeded the time limit allocated. Please check for infinite loops or other similar scenario in your code:

for Find a Route (Id-1533)




0



0

Reply

Leave a Reply:

This site uses cookies and by using the site you are consenting to this.