Rahul is fond of travelling and he visits cities and towns in the country whenever possible. All cities in the country a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Rahul is fond of travelling and he visits cities and towns in the country whenever possible. All cities in the country a

Post by answerhappygod »

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, the 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 the current city and there is more than
one city from the current city, he sorts the city names and
includes the first minimum city name that is not yet visited. For
example, if the connection between the cities is 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.
City Connected
Cities
A E, B
B D
C E,D
D F
E
F
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
(Need Code in C++)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply