I am using the colors 0 and 1 to color the graph and -1 for the vertices which are not yet discovered. But I am getting WA in the problem. Please help me out
It is not necessary that graph is a connected graph. So make a outer loop from 1 to n check if vertex is not visited then bfs part while(!q.empty()) and rest of the code same.Hope this helps !!