Minimum Teleporter Repairs
Problem statement
Countries have directed teleport connections. Some countries have a broken departure teleporter, which takes one day to repair before it can be used. Find the minimum number of repair days needed to travel from source to destination; teleporting itself takes zero days.
For this exercise, assume countries are numbered 0..n-1, and each [a,b] connection permits travel from a to b. A broken teleporter belongs to its departure country, regardless of which outgoing connection is chosen. Arrival at a broken destination does not require repair. A teleporter stays repaired after its first repair; an optimal route can be chosen without repeated countries.
For this exercise, return -1 if no directed route exists and 0 if the endpoints coincide. Repeated edges and repeated entries in broken do not change the answer.
Function
minTeleporterRepairs(n: int, connections: int[][], broken: int[], source: int, destination: int) → intExamples
Example 1
n = 7connections = [[0,1],[0,2],[0,3],[1,2],[1,5],[2,3],[2,4],[2,5],[3,4],[3,6],[5,6]]broken = [5]source = 1destination = 6return = 0The reported path 1 -> 2 -> 3 -> 6 avoids departing from the broken teleporter at 5.
Example 2
n = 7connections = [[0,1],[0,2],[0,3],[1,2],[1,5],[2,3],[2,4],[2,5],[3,4],[3,6],[5,6]]broken = [1,5]source = 1destination = 6return = 1Every nontrivial route departs from the broken source at 1, but 1 -> 2 -> 3 -> 6 requires no additional repair.
Example 3
n = 2connections = [[0,1]]broken = []source = 1destination = 0return = -1There is no directed route from country 1 back to country 0.
Constraints
- For this exercise, assume
1 <= n <= 2000and at most10000directed connections. - Every country index, including endpoints and broken entries, lies in
[0,n-1]. broken.length <= 2000; repeated entries and self-connections are allowed.