Amazon Interview Question

question on multisource bfs