Citadel Interview Question

a problem about graph and bfs