Tests if a graph is bi-colorable and outputs its connected components