Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2021 /round3 /perf-ore-mance.md
wjomlex's picture
2021 Problems
d3f4f72 verified
|
raw
history blame
3.83 kB

Facebulk Inc. is a mining company that's about to release its latest performance report. In these trying times, accurate numbers will be crucial. As a forensic accountant, you've been hired to secretly audit employee earnings across (T) ore-processing plants.

A given plant has (N) employees. Employee (1) is the superintendent, and has no manager. Each other employee (i) has a single direct manager, employee (M_i) ((1 \le M_i < i)). With access to the HR database, you have full knowledge of the company structure.

The HR database also contains each employee's individual earnings in dollars, which is possibly zero or negative (if the employee lost money). However, the database's anonymization scheme prevents you from directly looking up an employee's individual earnings, instead supporting the following two types of queries which may be performed as many times as you like:

  1. For a given employee (i), query the sum of the earnings of all employees directly managed by employee (i) (only allowed if there are at least (K) such employees)
  2. For a given employee (i), query the sum of the earnings of all employees either directly or indirectly managed by employee (i) (only allowed if there are at least (K) such employees)

Despite the indirect nature of these queries, with each result being the sum of earnings of at least (K) employees, you may still be able to infer some earnings of individual employees.

However, you're not necessarily satisfied with that. As a proficient hacker, you've figured out how to drop employees from the HR database. Before performing any queries, you may choose to delete (0) or more employees (along with their earnings) from the company structure and database. You can only delete an employee if they do not directly manage anyone still in the database at the time.

Assuming you optimally decide which employees to delete and make the most of the database queries, what's the maximum possible number of employees whose earnings you can determine?

Constraints

(1 \le T \le 60) (1 \le N \le 800{,}000) (2 \le K \le 10) (1 \le M_i < i)

The sum of (N) across all plants is at most (4{,}000{,}000).

Input

Input begins with an integer (T), the number of ore-processing plants. For each plant, there is first a line containing (2) space-separated integers, (N) and (K). Then, there is a second line containing (N-1) space-separated integers (M_{2..N}).

Output

For the (i)th plant, print a line containing "Case #i: " followed by a single integer, the maximum possible number of employees whose earnings you can determine after a round of deletions.

Sample Explanation

In the first plant, the company structure looks as follows:

{{PHOTO_ID:575117230498780}}

If you don't delete any employees, you can determine the earnings of employee (2) as follows. If ($X) is the result of query type 2 for employee (1) (the sum of employee (2), (3), and (4)'s earnings), and ($Y) is the result of query type 1 for employee (2) (the sum of employee (3) and (4)'s earnings), then employee (2)'s earnings must then be equal to ($X - $Y). No other employees' earnings can be determined.

In the second plant, the company structure looks as follows:

{{PHOTO_ID:281780436953175}}

One option is to delete employees (3), (5), and (7). This yields a company structure just like the one in the first plant, with employee (2)'s earnings becoming possible to determine. It's impossible to simultaneously determine multiple employees' earnings.

In the third plant, the only value which may be queried is the sum of the earnings of employees (2), (3), (4), and (5) (and only if none of them are deleted). This does not allow any individual employee's earnings to be determined.