This page is still under construction.

Parts of this page are still being built. What you see may change.

Another Crisis

Time limit1sMemory limit128 MB

Summary
Given a company tree and a threshold T percent, find the minimum number of leaf workers who must petition so that a petition reaches the root.
Level

Medium6 of 10

Topics
Tree, DFS, Greedy, Dynamic programming
Solved
No attempts yet

Problem

A few years ago a worldwide crisis began, leaving many people in economic trouble. The workers of a certain company want to ask for a raise.

The company has a strict hierarchy: every employee has exactly one direct boss, except for the company's owner, who has no boss. An employee who is nobody's boss is called a worker. Everyone else, together with the owner, is called a boss.

To ask for a raise, a worker files a petition to their direct boss. Naturally, each boss would rather keep their subordinates content on their current pay so that the company's profit stays as high as possible. However, once at least TT percent of a boss's direct subordinates have filed a petition, that boss is pressured into filing a petition to their own direct boss as well. A boss files at most one petition to their own boss, no matter how many subordinates petitioned them. When computing the pressure percentage, a boss counts only their direct subordinates (both the ones who filed a petition and the ones who did not).

A boss may have both workers and lower bosses as direct subordinates at the same time, and may receive petitions from either kind. Each direct subordinate, whatever its kind, counts as 11 when checking the pressure percentage.

When a petition finally reaches the owner of the company, every salary is raised. The workers' union is determined to make this happen, so it must convince enough workers to petition their direct boss.

Given the company hierarchy and the parameter TT, determine the minimum number of workers who must file a petition so that the owner receives a petition.

Input

The input contains several test cases. Each test case is given on exactly two lines.

The first line contains two integers NN and TT (1≤N≤1051 \le N \le 10^5, 1≤T≤1001 \le T \le 100) separated by a single space. NN is the number of employees (not counting the owner) and TT is the parameter described above. Employees are identified by integers from 11 to NN, and the owner is identified by 00.

The second line contains NN integers separated by single spaces. The ii-th integer BiB_i (0≤Bi≤i−10 \le B_i \le i - 1) is the identifier of the direct boss of employee ii.

The last test case is followed by a line containing two zeros separated by a single space, which must not be processed.

Output

For each test case, output a single line containing one integer: the minimum number of workers who must file a petition so that the owner of the company receives a petition.

Examples1

  1. Example 1

    Input
    3 100
    0 0 0
    3 50
    0 0 0
    14 60
    0 0 1 1 2 2 2 5 7 5 7 5 7 5
    0 0
    
    Expected output
    3
    2
    5