breath first search and connected component