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

Team Coding

설명

The company Eindhoven Gigantic Open-Source Institute (EGOI) is structured in a very hierarchical way. Except for the CEO Anneke, each of the other \(N-1\) employees in the company has a unique boss that they report to, and there are no cycles in the hierarchy. You can think of the company hierarchy as a tree rooted in the vertex corresponding to Anneke. As this is a diverse company, the employees code in \(K\) different programming languages, but every employee has exactly one preferred programming language.

Anneke has a big new project for a team in her company to work on. She wants to put as many resources as possible into this project. To decide the team who will work on this, she does the following:
- Pick a person to lead the team. This will also define the programming language the project is coded in. Every employee who is in the subtree below the team lead and prefers the same programming language will work on the problem.
- Increase the number of employees who work on the project, by switching employees who prefer the same programming language as the team lead into her team.

To maximize the number of employees who work on the project, she can perform the following switching operation any number of times:
- She picks two employees:
- One employee who is currently in the subtree of the team lead and does not prefer the same programming language as the team lead.
- One employee who is not in this subtree at the moment and prefers the same programming language as the team lead. Additionally, this employee needs to be on the same level as the other chosen employee; that is, they need to have the same number of higher-ups in the report chain to Anneke. If you imagine the company hierarchy as a tree, then the two employees are on the same level of the tree.
- Those two employees (and only them – not any other employees) switch positions in the company hierarchy. Note that employees reporting to the two affected employees stay in place and just change whom they report to. In the example below, with employee \(4\) having been chosen as the team lead, we can swap employees \(3\) and \(2\) but not employees \(1\) and \(8\).

Find the maximum number of employees working on the new project you can reach and the minimum number of switching operations needed to achieve this.

(An illustrative figure from the official statement is omitted here.)

제약
  • \(1 \le N \le 10^5\).
  • \(1 \le K \le N\).

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.

|

Group | Score | Limits \(1\) | \(12\) | The direct boss of employee \(i\) is \(i-1\) for all \(1\le i. \(2\) | \(19\) | \(K\le 2\) \(3\) | \(27\) | For each programming language, there are at most \(10\) employees that prefer it \(4\) | \(23\) | \(N\le 2\,000\) \(5\) | \(19\) | No further constraints

입력 형식

The first line of the input contains two integers, \(N\) and \(K\), the number of employees of EGOI and the number of programming languages the employees might use.

The employees of EGOI are numbered from \(0\) to \(N-1\), and Anneke the CEO has number \(0\). The next line contains \(N\) integers \(\ell_i\) with \(0\le \ell_i, the preferred programming languages of the employees.

The next \(N-1\) lines contain the company structure. The \(i\)th line contains an integer \(b_i\) with \(0\le b_i, the direct boss of the \(i\)th employee. Note that \(i\) goes from \(1\) to \(N\), as Anneke, the CEO, does not have a boss.

출력 형식

Output a single line with two integers, \(P\) and \(S\), the maximum number of employees (including the team lead) working on the new project you can reach with any number of switches and the minimum number of switches needed to reach this.

서브태스크
서브태스크점수설명

Subtask 1

12점

None

Subtask 2

19점

None

Subtask 3

27점

None

Subtask 4

23점

None

Subtask 5

19점

None

예제 1
입력
5 3
0 1 2 2 1
0
1
2
3
출력
2 0
예제 2
입력
4 2
0 1 0 0
0
0
1
출력
3 0
예제 3
입력
9 3
0 0 2 1 2 0 2 1 2
4
8
1
0
4
1
0
7
출력
4 2
예제 4
입력
8 3
0 2 1 2 2 1 1 1
6
3
0
6
3
0
3
출력
3 2
문제 정보

rip 작성

출처 EGOI 2024

평가 및 의견

Team Coding

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

Log in to rate problems.

개별 의견

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

풀이 제출

Team Coding

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