Split rivals into two teams
There are n players numbered 0 to n - 1, and each pair [a, b] in rivals means players a and b refuse to play on the same team. Return True if the players can be split into two teams (one of them may be empty) so that no two rivals share a team, otherwise False.
n ≥ 1. In every pair a ≠ b; a pair may repeat, and some players may have no rivals at all.
Besides the tests, one large input (20 players) with a ~100 ms limit (scaled to your device's speed): brute force won't pass.
Examples
can_split(4, [[0,1],[1,2],[2,3],[3,0]])→truecan_split(3, [[0,1],[1,2],[2,0]])→falsecan_split(5, [[0,1],[2,3],[3,4],[4,2]])→false