Fixed issue when merging graphs with common ancestors.