Interstate Rescue Network Audit
The interstate rescue authority manages a network of service depots linked by highways so emergency crews can move quickly during storm season. Each depot is numbered from 0 to n - 1, and the authority documents every two-way highway connecting two depots. When a large storm warning is issued from one central depot, dispatchers relay the activation signal through connected depots to coordinate coverage. Some highways may close due to flooding or construction, preventing crews from traveling through those lanes until they reopen.
Implement a function that accepts the depot count n, a list of highways roads, the origin depot start, and a list closed_highways describing the specific lanes that are closed. Each highway is recorded as [u, v], indicating a two-way road between depots u and v. The list may repeat lanes or include reversed orderings such as [v, u]. The closed_highways parameter contains entries in the same format, representing pairs that crews must avoid. These closures apply in both directions. The origin depot is always active, and any depot unreachable without using a closed highway remains idle.
The function must return the number of depots that receive the activation. Duplicated roads should not affect the answer, and closed lanes cannot be used as shortcuts. Count the origin depot even if no other depots can be reached. If all roads remain open, the result matches the size of the connected component containing start. Provide the final number as an integer without formatting.
Example 1:
Input: n = 6, roads = [[0,1],[1,2],[2,3],[3,4],[4,5]], start = 0, closed_highways = [[2,3]]
Output: 3
Explanation: Depots 0, 1, and 2 receive the alert; the closure prevents reaching the rest.
Example 2:
Input: n = 5, roads = [[0,1],[1,2],[2,3],[3,4]], start = 4, closed_highways = []
Output: 5
Explanation: With no closures, the activation spreads to all depots.
Example 3:
Input: n = 4, roads = [[0,1],[1,2],[2,3]], start = 2, closed_highways = [[1,2],[2,3]]
Output: 1
Explanation: The origin depot is surrounded by closed highways, so only itself is active.
Related Problems
No related problems found
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
