Avoid repeated merging of the same chains of edges by processing all edges at once. Test cases for the issue.