for better understanding col array is used for coloring the vertices initially all vertices are white andvis array is used for checking that vertices is visited or not.
" if for each edge uv there is at least one endpoint of it in this set" So, you have take care of the fact that all the edges are covered. But in your code you are dealing with a single connected component.So, simply speaking if the graph is such that it has several independent parts then you have to take care of all the components.