let's trace a triangle: graph = [[1,2],[0,2],[0,1]]. Start: color = [-1,-1,-1]. BFS from . Color as . Queue: [0]. Pop . Neighbors: , . Color as , color as . Queue: [1, 2]. Pop . Neighbors: , .
Node has color (opposite of , good). Node has color (same as ). Conflict! Return false. The triangle is an odd cycle. You caught it the moment two neighbors tried to have the same color.