Update merge_groups.cpp

allow merging of more than two adjacency groups