check whether vertices exist when inserting edge
do not insert duplicate vertices