Given n people (1-indexed) and an array dislikes where dislikes[i] = [a, b] means person a and b dislike each other. Return true if and only if it is possible to split everyone into two groups.
"People are nodes (1 to n). Dislike pairs are undirected edges: two people who dislike each other cannot share the same group. This is 2-coloring."
"The input is 1-indexed. Allocate arrays of size $n+1$ to avoid off-by-one errors: color = new int[n + 1]."
"Iterate 1..n. For each uncolored component, assign Color 1. For each neighbor $v$, if uncolored assign $3 - color[u]$ (swaps between 1 and 2). If neighbor has same color, return false immediately."
"Building the graph takes $O(E)$. BFS visits each person and dislike edge once. Total time is $O(V + E)$ and auxiliary space is $O(V + E)$."