I would iterate through all triangles and generate a list of needed vertices by using a STL container like set or map or something like that.