need help in applying bipartite graph

div 1 problem of codeforces
link -
code link -
why giving wrong output in test case -15

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.

Add this line of code :

for(int j = 1; j <= n; j++) if(!vis[j]) bfs(j);