connect_subgraphs function

Merge disjoint connected subgraphs