P1543 [POI 2004] SZP

Background

The class beauty [\color{red}{\texttt{y}}\color{black}{\texttt{hb}}](/user/835809) is very cute.

Description

During a self-study period, the class beauty [\color{red}{\texttt{y}}\color{black}{\texttt{hb}}](/user/835809), serving as the duty class monitor for the day, manages $n$ students. Every student except her monitors another student. Now the class beauty [\color{red}{\texttt{y}}\color{black}{\texttt{hb}}](/user/835809) needs to choose as many students as possible to carry exam papers and answer sheets, such that for every chosen student, at least one student who monitors her is not chosen. How many students can she choose at most? Because the class beauty [\color{red}{\texttt{y}}\color{black}{\texttt{hb}}](/user/835809) is so cute, no one monitors her; you can think of her ID as $0$. If a person is not monitored by anyone, then she cannot be chosen.

Input Format

The first line contains a single integer, $n$, representing the number of students. Students are numbered from $1$ to $n$. The next $n$ lines each contain an integer $a_k$ indicating that student $k$ will monitor student $a_k$, $1 \le k \le n$, $1 \le a_k \le n$, $a_k \ne k$.

Output Format

A single integer, the maximum number of students who can take part in this task.

Explanation/Hint

For $100\%$ of the testdata, $1 \le k, a_k \le n \le 10^6$. Translated by ChatGPT 5