Adding connected components for undirected graphs.