[Modify] modify the algorithms to add edges of existing nodes