RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 ICPC00130

K. Gastronomic Event

설명

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 \le n \le 1\,000\,000\)) — the number of rooms. The second line contains \(n - 1\) integers \(p_{2}\), \(p_{3}\), · · · , \(p_{n}\) (\(1 \le 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
출력
13
예제 2
입력
10
1 2 3 4 3 2 7 8 7
출력
47
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC SWERC 2021

평가 및 의견

K. Gastronomic Event

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

K. Gastronomic Event

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8