Implement dynamic computation of connected components.