graphs: connected component using BFS code