Your approach is correct. You cannot do it better.
The reason it works is that if you mark the vertices with their depth during the execution of the BFS, then all the edges connect the same marks or marks that are different from each other. It is clear that if there is an edge connecting the same labels, then there is an odd cycle. If not, then we can color all the odd labels white, and all the even labels black.
Petar Ivanov
source share