Question: Sample Input 0 4 6 0 1 2 0 1 0 2 0 1 2 1 0 2 0 1 0 1 3 3 0
Sample Input
Sample Output
Explanation
Explanation For example, Let us calculate the round trip between City and City ie
Cost because there are only one simple way to go to there.
Cost
So the cheapest round trip from City and City ie is equal to units.
We can calculate all the other round trip in the similar way, then we can get the answer which is ie
There are city pairs with the lowest cost and
Lowest sum of indices belongs to & hence and in alphanumeric order.
Sample Input
Sample Output
Explanation
There is no return flights from any combination of cities. Hence the answers.Cheap Airfare
Problem Statement
Anjali has started a new travel agency. She noticed that the air fares between the cities are not
symmetrical. That is the cost of flying from to is not the same as that of to Further, there is no
guarantee that once you fly directly from to there is a direct return flight.
She knows that passengers do not mind changing flights as long as the total airfare is minimized. She
needs to advertise the lowest round trip cost between any pair of cities of tourist interest to attract
potential passengers. All valid flights ie where is the source city of tourist interest, is the
destination city of tourist interest and is the price of the ticket.
You must help her determine the lowest round trip cost & the cities involved.
Input Format
The first line consists of integer indicating the number of cities
The second line consists of integer indicating the number of flights
Each of the next lines contains integers separated by a space starting city A end city B and the
price of the ticket for flight from to
Constraints
Number of cities
Number of flights
Price
Output Format
Return an array of integers. st integer is the price for the cheapest round trip. nd and rd integers are
the city indices involved in increasing order.
If there is no round trip available, return and
If there are multiple pair of cities with lowest round trip fair, please select the pair with the lowest sum of
their indices.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
