#P2661. [NOIP 2015 提高组] 信息传递
[NOIP 2015 提高组] 信息传递
Description
There are players (numbered from to ) playing an information transfer game. In this game, each player has a fixed designated recipient. Specifically, the designated recipient of player is player .
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 lines.
The first line contains positive integer , representing the number of players.
The second line contains space-separated positive integers . Here, the -th integer means that the designated recipient of player is player , with and .
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 rd round, player will hear player tell him his own birthday, so the answer is . Of course, after the rd round, player and player can also learn their own birthdays from their respective sources, which also satisfies the game’s end condition.
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号