adding an output iterator to count the number of vertices