Adapt the internal function MergeEdges to the case when on input it takes a set of edges constituting several connected chains.