Interstate Rescue Network Audit
Interstate Rescue Network Audit is a reachability count problem on an undirected road graph with selective closures. You receive the total depot count, a list of two-way highways, a starting depot, and a list of blocked highway references. Your task is to compute how many depots can still be reached from the start when those blocked routes are removed from traversal.
The reliable approach is graph traversal after filtering blocked links. Build adjacency using only open highways, then run BFS or DFS from the starting depot and count unique visited depots. Duplicate highways should not inflate counts, and disconnected components that are not connected to the origin must be ignored. If closures isolate the start, the answer is just the starting depot itself.
Judge behavior emphasizes correctness under partial shutdown conditions: chain networks cut in the middle, sparse graphs with separated islands, and cases where blocked routes leave only a tiny reachable component. Return a single integer count only. The core challenge is maintaining exact traversal constraints so every open depot is counted once and only once, while blocked links are treated as fully unavailable regardless of their direction in the original input list.
In implementation terms, treat closed-highway references consistently with the same indexing convention used by the input provider, then construct traversal edges only from allowed routes. This prevents accidental leakage through blocked links and keeps results aligned when route lists include repeated or symmetric entries.
Examples
Depots 0, 1, and 2 receive the alert; the closure prevents reaching the rest.
With no closures, the activation spreads to all depots.
The origin depot is surrounded by closed highways, so only itself is active.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int rescue_network_reach(int n, int[][] roads, int start, int[][] closed_highways) {
Set<String> closed = new HashSet<>();
for (int[] r : closed_highways) {
int u = Math.min(r[0], r[1]);
int v = Math.max(r[0], r[1]);
closed.add(u + "-" + v);
}
Map<Integer, List<Integer>> adj = new HashMap<>();
for (int[] r : roads) {
int u = Math.min(r[0], r[1]);
int v = Math.max(r[0], r[1]);
if (!closed.contains(u + "-" + v)) {
adj.computeIfAbsent(r[0], k -> new ArrayList<>()).add(r[1]);
adj.computeIfAbsent(r[1], k -> new ArrayList<>()).add(r[0]);
}
}
Set<Integer> visited = new HashSet<>();
Queue<Integer> queue = new LinkedList<>();
visited.add(start);
queue.offer(start);
while (!queue.isEmpty()) {
int u = queue.poll();
if(adj.containsKey(u)) {
for (int v : adj.get(u)) {
if (visited.add(v)) {
queue.offer(v);
}
}
}
}
return visited.size();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
