P10933 Genesis.
Description
God has $N$ types of world elements. Each element can restrain exactly $1$ other element. Let the element that the $i$-th world element can restrain be $A[i]$.
Now, God wants to place some of them into a new space to build a world.
For the peace and safety of the world, God hopes that for every placed world element, there exists at least one world element that can restrain it that is not placed.
God wants to know: under this condition, what is the maximum number of world elements he can place?
Input Format
The first line contains an integer $N$, representing the number of world elements.
The second line contains $N$ integers $A[1], A[2], \dots, A[N]$. $A[i]$ represents the index of the world element that the $i$-th world element can restrain.
Output Format
Output one integer, representing the maximum number of world elements that can be placed.
Explanation/Hint
Constraints: $1\le N \le 10^6$, $1 \le A[i] \le N$.
Translated by ChatGPT 5