Employees are numbered from 0 through n-1, and favorite[i] is the person employee i wants to sit beside. Choose a subset of employees and arrange them around one circular table. Every chosen employee must have their favorite person immediately next to them on either side. Each employee can occupy only one seat, and the table can hold any number of people. Return the largest number you can seat while satisfying everyone. No employee lists themself as their favorite.
Example 1:
Input: favorite = [1,0,0,1]
Output: 4Explanation: Seat employees in circular order 2, 0, 1, 3. Employee 2 sits beside favorite 0, employees 0 and 1 sit beside each other, and employee 3 sits beside favorite 1. All four can attend.
Example 2:
Input: favorite = [1,0,3,2]
Output: 4Explanation: The favorite pairs are 0 with 1 and 2 with 3. Circular order 0, 1, 2, 3 keeps both pairs adjacent, so all four employees can attend.
Example 3:
Input: favorite = [1,2,0,0]
Output: 3Explanation: Employees 0, 1, and 2 can sit in that circular order. Their favorite relationships require all three edges of the triangle between them. Adding employee 3 beside 0 would break a required adjacency, so the maximum is 3.
Constraints:
2 <= n <= 1000000 <= favorite[i] < nfavorite[i] != i