Check for the same vertex in build_graph