[USACO17DEC] The Bovine Shuffle S

题意翻译

背景 FJ 坚信快乐的牛可以产出更多的牛奶,因此 FJ 在牛棚里安装了一个巨大的迪斯科球并且打算让奶牛们学会跳舞。 FJ在许多出名的奶牛舞中选择了一种叫做 `Bovine Shuffle` 的舞蹈。这种舞蹈由 FJ 的 $N$ 头奶牛组成。$N$ 头奶牛以一种顺序排成一行,接着表演数次 `shuffle`。每次的 `shuffle` 会将奶牛重新排列。FJ 为了让奶牛们更加快乐,让奶牛们更容易找到重新排列后的位置,他标记了 $N$ 头奶牛的位置。在最开始,所有奶牛排成一排,第一头奶牛会在位置 $1$ 上,第二只在 $2$ 上,以此类推。 我们用 $N$ 个正整数 $a_1,a_2\dots a_n$ 来描述每次的 `shuffle`。$a_i$ 说明了在位置 $i$ 上的奶牛在经过这回合的 `shuffle` 之后,会跑到位置 $a_i$ 上。令 FJ 倍感非洲的是,即使 $i$ 与$j$ 不同,$a_i$ 也可能会等于 $a_j$ !所以可能在一次 `shuffle` 后,有多头奶牛会跑到同一位置上,在这之后这群奶牛也会一同行动。 作为一名资深的养牛大户&坑牛专家的 FJ 猛然发现,无论经过多少次的 `shuffle`,一直都有 $k$ 个位置上有奶牛。FJ现在要你在 $1$ 秒内帮他得出 $k$ 的值,否则就赏你 $10^{18} \bmod10$ 大板! 输入格式 第一行包含一个整数,$N$ 第二行包含 $N$ 个整数,描述题目中的$a_1,a_2\dots a_n$ 输出格式 一个整数,代表 $k$

题目描述

Convinced that happy cows generate more milk, Farmer John has installed a giant disco ball in his barn and plans to teach his cows to dance! Looking up popular cow dances, Farmer John decides to teach his cows the "Bovine Shuffle". The Bovine Shuffle consists of his $N$ cows ($1 \leq N \leq 100,000$) lining up in a row in some order, then performing successive "shuffles", each of which potentially re-orders the cows. To make it easier for his cows to locate themselves, Farmer John marks the locations for his line of cows with positions $1 \ldots N$, so the first cow in the lineup will be in position 1, the next in position 2, and so on, up to position $N$. A shuffle is described with $N$ numbers, $a_1 \ldots a_N$, where a cow in position $i$ moves to position $a_i$ during the shuffle (and so, each $a_i$ is in the range $1 \ldots N$). Every cow moves to its new location during the shuffle. Unfortunately, all the $a_i$'s are not necessarily distinct, so multiple cows might try to move to the same position during a shuffle, after which they will move together for all remaining shuffles. Farmer John notices that some positions in his lineup contain cows in them no matter how many shuffles take place. Please help him count the number of such positions.

输入输出格式

输入格式


The first line of input contains $N$, the number of cows. The next line contains the $N$ integers $a_1 \ldots a_N$.

输出格式


Please output the number of positions that will always contain cows, no matter how many shuffles take place.

输入输出样例

输入样例 #1

4
3 2 1 3

输出样例 #1

3