Disaster Relief Route Tracker
Disaster Relief Route Tracker is a connectivity count problem with blocked shelters. You get the number of shelters, undirected roads, a start shelter, and a list of blocked shelter IDs. Count how many open shelters are reachable from the start without passing through blocked shelters.
Build graph adjacency, mark blocked shelters, and run BFS or DFS while skipping blocked nodes. If the start is blocked, reachability is zero in a strict interpretation; in this dataset the start is open in tested cases, and traversal should count each reachable open shelter once. Duplicate roads should not create duplicate visits, so maintain a visited set throughout the traversal.
Judge scenarios include partially blocked graphs, disconnected components, and cases where one blocked hub sharply reduces coverage. Return only the integer count. The important implementation detail is node-level blocking (shelters), not edge-level blocking, so checks happen before visiting nodes and when iterating neighbors. With clean filtering and one traversal pass, the result stays deterministic and consistent across sparse and dense road maps.
Keep blocked-shelter checks on both queue insertion and neighbor expansion so blocked nodes are never traversed indirectly. This ensures computed coverage matches operational rules where closed shelters cannot relay routes, even if they still appear in adjacency lists from raw road data.
Examples
The convoy reaches shelters 1, 0, 2, 3, and 5 while skipping the blocked shelter 4.
With no roads, only the staging shelter receives supplies.
The convoy can only deliver to shelters 0 and 1 before encountering a blocked location.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int disaster_relief_route_tracker(int n, int[][] roads, int start, int[] blocked_shelters) {
Set<Integer> blocked = new HashSet<>();
for (int s : blocked_shelters) blocked.add(s);
if (blocked.contains(start)) return 0;
List<Integer>[] adj = new ArrayList[n];
for (int i = 0; i < n; i++) adj[i] = new ArrayList<>();
for (int[] road : roads) {
adj[road[0]].add(road[1]);
adj[road[1]].add(road[0]);
}
Set<Integer> visited = new HashSet<>();
Queue<Integer> queue = new LinkedList<>();
visited.add(start);
queue.add(start);
while (!queue.isEmpty()) {
int u = queue.poll();
for (int v : adj[u]) {
if (!visited.contains(v) && !blocked.contains(v)) {
visited.add(v);
queue.add(v);
}
}
}
return visited.size();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
