BFS implementation on an undirected graph.