QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 100 Hackeable ✓

#15292. Information Transmission

Estadísticas

There are $n$ students (numbered $1$ to $n$) playing a message-passing game. In the game, everyone has a fixed message-passing target, where the message-passing target of the student numbered $i$ is the student numbered $T_i$.

At the start of the game, each student only knows their own birthday. In each subsequent round, everyone simultaneously tells their current known birthday information to their respective message-passing target (Note: it is possible for a person to receive information from multiple people, but each person will only tell their information to one person, i.e., their own message-passing target). When a person learns their own birthday from someone else, the game ends. How many rounds can this game last in total?

Input

The input consists of two lines.

The first line contains one integer $n$, representing $n$ students.

The second line contains $n$ space-separated integers $T_1, T_2, \dots, T_n$, where the $i$-th integer represents that the message-passing target of the student numbered $i$ is the student numbered $T_i$, with $1 \le T_i \le n$ and $T_i \neq i$.

It is guaranteed that the game will always end.

Output

Output one line containing a single integer, representing the total number of rounds the game lasts.

Examples

Input 1

5
2 4 2 3 1

Output 1

3

Note 1

The game process is shown in the figure. After the 3rd round of the game, student 4 hears student 2 tell them their own birthday, so the answer is 3. Of course, after the 3rd round, student 2 and student 3 can also learn their own birthdays from their own information sources, which also meets the conditions for the game to end.

Input 2

(See message/message2.in in the problem directory)

Output 2

(See message/message2.ans in the problem directory)

Constraints

For 30% of the data, $n \le 200$; For 60% of the data, $n \le 2500$; For 100% of the data, $n \le 200000$.

Figure 1. The game process showing the message passing over 3 rounds.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.