#P5958. [POI 2017] Sabotaż

[POI 2017] Sabotaż

Problem Description

A company has nn people, and the superior-subordinate relationships form a rooted tree. There is one traitor (it is unknown who it is).

For a person, if among their subordinates (direct or indirect, not including themself), the proportion of traitors exceeds xx, then this person will also become a traitor, and all of their subordinates will become traitors as well. You need to find the minimum xx such that, in the worst case, the number of traitors will not exceed kk.

Input Format

The first line contains two positive integers n,kn, k.

In the next n1n - 1 lines, the ii-th line contains a positive integer pi+1p_{i+1}, meaning that the parent of i+1i + 1 is pi+1p_{i+1}.

Output Format

Output one real number xx. Any answer with an absolute or relative error within 10610^{-6} is accepted.

9 3
1
1
2
2
2
3
7
3
0.6666666667

Hint

Sample Explanation

In the answer, xx is actually a number that approaches 23\frac{2}{3} infinitely closely but is greater than 23\frac{2}{3}.

Because when x=23x = \frac{2}{3}, in the worst case, 3,7,8,93, 7, 8, 9 are all traitors, which exceeds k=3k = 3.

Constraints

For 100%100\% of the testdata, 1kn5000001 \le k \le n \le 500000, 1pi+1i1 \le p_{i+1} \le i.

Translated by ChatGPT 5