Added a getter for the number of connected components.