The algorithm is almost identical to :
Build adjacency list from dislikes.
Create color array of size , all .
For each person from to : if color[i] == -1, run BFS from .
In BFS: color start as .
For each neighbor: if uncolored, assign opposite color, add to queue. If same color, return false.
If all done without conflict, return true.
This runs in time and uses space.