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

32109번 - Team Coding 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB136541.667%

문제

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:

  1. 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.
  2. 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:
    1. She picks two employees:
      1. One employee who is currently in the subtree of the team lead and does not prefer the same programming language as the team lead.
      2. 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.
    2. 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.

입력

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<K,ドル 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<N,ドル 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.

제한

  • 1ドル \le N \le 10^5$.
  • 1ドル \le K \le N$.

서브태스크

번호배점제한
112

The direct boss of employee $i$ is $i-1$ for all 1ドル\le i<N$.

219

$K\le 2$

327

For each programming language, there are at most 10ドル$ employees that prefer it

423

$N\le 2,000円$

519

No further constraints

예제 입력 1

5 3
0 1 2 2 1
0
1
2
3

예제 출력 1

2 0

예제 입력 2

4 2
0 1 0 0
0
0
1

예제 출력 2

3 0

예제 입력 3

9 3
0 0 2 1 2 0 2 1 2
4
8
1
0
4
1
0
7

예제 출력 3

4 2

예제 입력 4

8 3
0 2 1 2 2 1 1 1
6
3
0
6
3
0
3

예제 출력 4

3 2

노트

In the first two samples, the company structure looks as follows, where the pattern encodes the programming language (0 = "striped", 1 = "dotted", 2 = "plain"):

In sample 1, we can choose employee 1ドル$ as the team lead with employee 4ドル$ preferring the same programming language and there are no possible switches to improve this. In sample 2, the full company has 3ドル$ employees preferring language 0ドル$ which is also Anneke's preferred language, so choosing Anneke as the team lead gives a team of size 3ドル$ with no switches needed.

In sample 3, we choose employee 4ドル$ as the team lead and then we can have employees 1ドル$&8ドル$ and 2ドル$&3ドル$ switch teams to get a total of 4ドル$ employees preferring the same language as 4ドル,ドル namely language 2ドル$ (yellow/plain). In sample 4, the maximum score can be obtained by choosing employee 6ドル$ as the team lead and switching employees 4ドル$&7ドル$ and 1ドル$&5ドル$. Note that we cannot switch employees 6ドル$&3ドル$ before choosing the team lead to get a score of 4ドル$ because we have to fix the team lead first.

출처

Olympiad > European Girls' Olympiad in Informatics > EGOI 2024 > Day 1 C번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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