seen
to keep track of visited nodes, initializing all entries to false
.restricted
nodes as visited in the seen
array.0
, marking it as visited.ans
to 0
, which will keep count of the reachable nodes.curr_node
from the queue.
b. Increment ans
by 1.
c. For each neighbor of curr_node
, if it is not visited, mark it as visited and enqueue it.ans
as the result.