Imagine you're organizing a debate tournament and need to split n people (labeled from 1 to n) into two opposing teams of any size. However, some people have personal conflicts and absolutely refuse to be on the same team!
You're given an integer n representing the total number of people and an array dislikes where dislikes[i] = [a_i, b_i] indicates that person a_i dislikes person b_i (and vice versa - it's mutual). Your task is to determine if it's possible to split everyone into exactly two teams such that no two people who dislike each other end up on the same team.
Return true if such a division is possible, false otherwise.
Example: If person 1 dislikes person 2, and person 2 dislikes person 3, then we could put persons 1 and 3 on Team A, and person 2 on Team B.
Input & Output
Constraints
- 1 โค n โค 2000
- 0 โค dislikes.length โค 104
- dislikes[i].length == 2
- 1 โค dislikes[i][j] โค n
- ai < bi
- All the pairs of dislikes are unique