I was doing a problem on SPOJ SPOJ:BUGLIFE It required me to check whether the graph was bipartite or not. I know the method for a single connected graph, but for a combination of disconnected graphs, my method gives Time limit exceeded error. Here's my approach - Breadth First Search, using Circular Queues with the graph implemented by adjacency lists. method -> Choose a source, and if that source vertex=unvisited, then start a Breadth First Search assuming it to be the source. If I found a conflict in the BFS, then I abort the whole thing. Else I move to another un-visited source. How can I make this faster? or better?
P.S. I am new to Graph Theory, so please explain in detail.