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

25063번 - Gastronomic Event 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 2048 MB103524047.059%

문제

SWERC organizers want to hold a gastronomic event.

The location of the event is a building with $n$ rooms connected by $n - 1$ corridors (each corridor connects two rooms) so that it is possible to go from any room to any other room.

In each room you have to set up the tasting of a typical Italian dish. You can choose from $n$ typical Italian dishes rated from 1ドル$ to $n$ depending on how good they are ($n$ is the best possible rating). The $n$ dishes have distinct ratings.

You want to assign the $n$ dishes to the $n$ rooms so that the number of pleasing tours is maximal. A pleasing tour is a nonempty sequence of rooms so that:

  • Each room in the sequence is connected to the next one in the sequence by a corridor.
  • The ratings of the dishes in the rooms (in the order given by the sequence) are increasing.

If you assign the $n$ dishes optimally, what is the maximum number of pleasing tours?

입력

The first line contains an integer $n$ (2ドル ≤ n ≤ 1,000円,000円$) — the number of rooms.

The second line contains $n - 1$ integers $p_2,ドル $p_3,ドル $\cdots,ドル $p_n$ (1ドル ≤ p_i < i$). Each $p_i$ indicates that there is a corridor between room $i$ and room $p_i$. It is guaranteed that the building has the property that it is possible to go from any room to any other room.

출력

Print the maximum number of pleasing tours.

제한

예제 입력 1

5
1 2 2 2

예제 출력 1

13

Explanation of sample 1.

It is optimal to place the dish with rating 1ドル$ in room 1ドル,ドル the dish with rating 2ドル$ in room 3ドル,ドル the dish with rating 3ドル$ in room 2ドル,ドル the dish with rating 4ドル$ in room 5ドル$ and the dish with rating 5ドル$ in room 4ドル$.

All the 13ドル$ possible pleasing tours are: $(1),ドル $(2),ドル $(3),ドル $(4),ドル $(5),ドル $(1, 2),ドル $(3, 2),ドル $(2, 4),ドル $(2, 5),ドル $(1, 2, 4),ドル $(1, 2, 5),ドル $(3, 2, 4),ドル $(3, 2, 5)$.

There are also other ways to assign the dishes to the rooms so that there are 13ドル$ pleasing tours.

예제 입력 2

10
1 2 3 4 3 2 7 8 7

예제 출력 2

47

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2021-2022 K번

  • 문제를 만든 사람: Cesc Folch
(追記) (追記ここまで)

출처

대학교 대회

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

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