Finished method to check if a graph is bipartite or not