spoj BUGLIFE WA

Problem link: SPOJ.com - Problem BUGLIFE

My solution: http://code.geeksforgeeks.org/uLsQi4 uses bfs

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

EDIT:-
Used the loop for all the nodes and still getting WA.
Code at http://code.geeksforgeeks.org/vVfXkd

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 !!

Thanks for the reply but I am still getting the WA …Check the code at http://code.geeksforgeeks.org/vVfXkd

@damn_me @betlista … Please help me out