#P2661. [NOIP 2015 提高组] 信息传递

[NOIP 2015 提高组] 信息传递

Description

There are nn players (numbered from 11 to nn) playing an information transfer game. In this game, each player has a fixed designated recipient. Specifically, the designated recipient of player ii is player TiT_i.

At the start of the game, each player knows only their own birthday. Then in each round, all players simultaneously tell all the birthday information they currently know to their designated recipient (note: someone may receive information from several people, but each person tells information to exactly one person, i.e., their designated recipient). The game ends when someone learns their own birthday from someone else. How many rounds can the game proceed in total?

Input Format

The input consists of 22 lines.

The first line contains 11 positive integer nn, representing the number of players.

The second line contains nn space-separated positive integers T1,T2,,TnT_1, T_2, \cdots, T_n. Here, the ii-th integer TiT_i means that the designated recipient of player ii is player TiT_i, with TinT_i \leq n and TiiT_i \neq i.

Output Format

Output a single integer on one line, indicating how many rounds the game proceeds in total.

5
2 4 2 3 1
3

Hint

Sample 1 explanation:

The process of the game is shown in the figure. After the 33rd round, player 44 will hear player 22 tell him his own birthday, so the answer is 33. Of course, after the 33rd round, player 22 and player 33 can also learn their own birthdays from their respective sources, which also satisfies the game’s end condition.

Constraints:

  • For 30%30\% of the testdata, n200n \le 200.
  • For 60%60\% of the testdata, n2500n \le 2500.
  • For 100%100\% of the testdata, n2×105n \le 2 \times 10^5.

Translated by ChatGPT 5