Logo
(追記) (追記ここまで)

20582번 - Family photo 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB53171760.714%

문제

Bitian family is just having a family gathering. Family members are numbered with consecutive numbers from 1ドル$ to $n$. Bityslav is the oldest family member and number 1ドル$ was associated to him. Each of the remaining family members has exactly one parent (kinda weird, but let it be).

Such wonderful family gathering needs to be documented well and there needs to be a photo taken. This photo will depict some of family members arranged in a row. However, this year family members are very choosy. Two members agree to stand next to each other if and only if one of them is an ancestor of the second one (not necessarily an immediate one). We say that A is an ancestor of B if and only if A is either a parent of B or a parent of some of B's ancestors}

Bityslav has a hard task now as he would like as many family members on this photo as possible. What is the biggest number of people that can be present on it?

입력

The first line of input contains one integer $n$ (2ドル \le n \le 300,000円$) denoting number of Bitian family members. The second line contains $n-1$ integers $p_2, p_3, \ldots, p_n$ (1ドル \le p_i \le n,ドル $p_i \ne i$ for 2ドル \le i \le n$), where $p_i$ is an index of a parent of $i$-th family member. You can assume that there is no cycle in this genealogical tree, i.e. nobody is an ancestor of himself.

출력

You should output one integer which is the maximum possible number of family members present on a photo with respect to constraints set by family members.

제한

예제 입력 1

8
5 5 5 1 1 6 7

예제 출력 1

7

힌트

Following picture denotes genealogical tree of Bitian family. One of the optimal photos can contain members with numbers 7ドル,ドル 6ドル,ドル 8ドル,ドル 1ドル,ドル 2ドル,ドル 5ドル,ドル 3ドル$ in this order. It can be shown it is impossible to have all of them on one photo.

출처

Camp > Petrozavodsk Programming Camp > Summer 2020 > Day 1: Warsaw U Contest F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /