Rerouting Rapids
시간 제한1초메모리 제한2048 MB
숲 구조에서 일부 간선을 조상 쪽으로 옮길 수 있을 때, 한 정점으로 들어오는 최대 간선 수를 최소화한다.
문제
The famous East Manitoba river that flows through Edmonton consists of rapids. The river is a popular rafting destination, with many visitors coming to the river each summer. When a visitor enters a rapid , the current will take them to some unique other rapid , except when is the end of the river. Because water can only flow downhill, visitors can never flow back into the rapid at which they started. It is often the case that multiple rapids , flow into the same rapid .
Unfortunately, there have been many collisions lately in rapids that have many other rapids feeding into them, as many visitors may enter the same rapid at similar times, each being fed into it by a different rapid. You work for the City of Edmonton and have been tasked with rerouting some rapids to decrease the rate of collisions. If it’s possible for a visitor to start at some rapid and eventually reach another rapid , you may shortcut rapid to lead directly into rapid , setting .
You wish to reroute rapids in this manner to minimize the maximum number of rapids feeding into any given rapid. Report this minimum number.

Figure 1: Illustration of the second sample case. By rerouting rapid to lead directly to rapid , all rapids now have at most two rapids feeding into them.
입력
The first line of input contains one integer , the number of rapids in the river (). The second line contains integers (). If , then is the rapid that the th rapid feeds into. Otherwise, if , then the th rapid is at the end of the river. It is guaranteed that for exactly one of the indices , and there is no way to start at the th rapid and eventually return to it for any .
출력
Output the minimum possible highest number of rapids feeding into any given rapid, subject to rerouting as described above.