Cheapest Flights Within K Stops
Problem Statement:
Given a graph of n cities, each city represented by an integer city from 0 to n-1, and a connections matrix where connections[i][j] represents the flight cost from city i to city j if a flight exists, you are tasked with finding the cheapest flights that connect all cities within k stops.
You can start from any city and must visit each city exactly once. The connections between the cities represent the valid flights you can take.
Your task is to find the minimum total cost of flights that covers all cities.
Rules and Constraints:
- Graph Representation: The connections matrix connections is a 2D array of size n x n. If there is no direct flight between two cities i and j, then connections[i][j] will be infinity (represented by a very large number).
- Cost: The cost of a flight from city i to city j is represented by connections[i][j]. The cost of traveling between two cities i and j directly is the same as traveling between them in the opposite order.
- Number of Flights Within k Stops: Each city is visited exactly once, and there are at most k-1 flights between two cities.
- Time Complexity: The function should return the minimum total cost within the given time complexity limit of O(n^2 * 2^k).
- Space Complexity: The function's memory usage should not exceed the space complexity limit of O(n).
Example
Input: {"input_data":[1,2,3]}
Output: [1,2,3]