Investigation
You are given an integer n representing the number of cities numbered from 1 to n. You are also given a 2D integer array flights where flights[i] = [u, v, price] represents a directed flight from city u to city v with a cost of price.
You want to travel from city 1 to city n. Your task is to find and return an array of four integers containing:
- The minimum total price of such a route.
- The number of minimum-price routes (modulo 109+7).
- The minimum number of flights in a minimum-price route.
- The maximum number of flights in a minimum-price route.
You may assume that it is always possible to reach city n from city 1.
Example 1:
Input: n = 3, flights = [[1, 2, 1], [2, 3, 1], [1, 3, 2]]
Output: [2, 2, 1, 2]
Explanation:
Two routes cost 2:
- 1 -> 3 (Cost: 2, Flights: 1)
- 1 -> 2 -> 3 (Cost: 1 + 1 = 2, Flights: 2) Both routes tie for the lowest cost of 2.
Example 2:
Input: n = 3, flights = [[1, 2, 10], [2, 3, 10], [1, 3, 100]]
Output: [20, 1, 2, 2]
Explanation:
The cheapest route is 1 -> 2 -> 3 costing 20. There is exactly 1 such route. Since there's only one shortest route, both the minimum and maximum number of flights are 2.
Now Your Turn!
Pick the correct output for the given inputInput: n = 4, flights = [[1, 2, 1], [2, 4, 1], [1, 3, 1], [3, 4, 1], [1, 4, 2]]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 105
- 1 <= flights.length <= 2* 105
- flights[i].length = 3
- 1 <= u, v <= n
- 1 <= price <= 109