Implemented a breadth-first search for undirected graphs.