Wildlife Bridge Network Scan
In Wildlife Bridge Network Scan, you analyze an undirected graph to measure how much of the network can still be explored from a chosen start node while some nodes are restricted. Conceptually, this is a connected-component size query under node blocking: only open nodes can be visited, and paths cannot pass through closed ones.
A straightforward strategy is BFS or DFS with adjacency lists plus a blocked-node set. Begin from the start node if it is open, then traverse neighbors while skipping restricted nodes and already-visited nodes. The final answer is the count of distinct reachable open nodes, including the start when valid.
The judge checks multiple graph shapes, repeated edges, partitioned components, and cases where restrictions isolate entire regions. So correctness depends on clean traversal rules and consistent handling of blocked nodes at every step. Return a single integer count with no extra metadata. This challenge is less about advanced optimization and more about disciplined graph fundamentals: build neighbors correctly, enforce restrictions during traversal, and count unique reachable nodes exactly once.
Examples
Bridges 1 and 3 are closed, so hikers remain at bridge 2 only.
All bridges are open, so the survey covers bridges 4, 3, 5, and 6.
The survey reaches bridges 0, 1, 2, 3, and 5; bridge 4 remains closed.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int wildlife_bridge_reach(int n, int[][] paths, int start, int[] closed_bridges) {
List<List<Integer>> adj = new ArrayList<>();
for (int i = 0; i < n; i++) adj.add(new ArrayList<>());
Set<Integer> closed = new HashSet<>();
for (int b : closed_bridges) closed.add(b);
for (int[] path : paths) {
if (path[0] < n && path[1] < n) {
adj.get(path[0]).add(path[1]);
adj.get(path[1]).add(path[0]);
}
}
if (closed.contains(start)) return 0;
Set<Integer> visited = new HashSet<>();
Queue<Integer> queue = new LinkedList<>();
visited.add(start);
queue.add(start);
while (!queue.isEmpty()) {
int curr = queue.poll();
for (int neighbor : adj.get(curr)) {
if (!visited.contains(neighbor) && !closed.contains(neighbor)) {
visited.add(neighbor);
queue.add(neighbor);
}
}
}
return visited.size();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
