Determine number of connected components