Official algorithmic problem description and constraints.
Monocarp wants to throw a party. He has π friends, and he wants to have at least 2 of them at his party.
The π-th friend's best friend is ππ. All ππ are distinct, and for every πβ[1,π], ππβ π.
Monocarp can send invitations to friends. The π-th friend comes to the party if both the π-th friend and the ππ-th friend receive an invitation (note that the ππ-th friend doesn't have to actually come to the party). Each invitation is sent to exactly one of the friends.
For example, if π=[3,1,2,5,4], and Monocarp sends invitations to the friends [1,2,4,5], then the friends [2,4,5] will come to the party. The friend 1 won't come since his best friend didn't receive an invitation; the friend 3 won't come since he didn't receive an invitation.
Calculate the minimum number of invitations Monocarp has to send so that at least 2 friends come to the party.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.