Implement connected components