As we are dealing with graph , the input might come as a forest , thus start coloring from a node and if true is returned we 'll know that  we successfully colored the subpart of our   forest and we start coloring again from a new   uncolored node. This way we cover the entire forest.
for ( int i = 1 ; i <= N ; i ++ ) if ( colorArr [ i ] == -1 ) if ( twoColorUtil ( G , i , N , colorArr ) == false ) return false ; return true ; }