Implemented connected component algorithm.