#P5958. Minimum Threshold for Limited Traitors

    ID: 19183 Type: Default 1000ms 256MiB

Minimum Threshold for Limited Traitors

Minimum Threshold for Limited Traitors

Given a company with \( n \) people forming a rooted tree (where person 1 is the root), exactly one person is initially a traitor (although we do not know which one).

The propagation rule is as follows: For any person, if the ratio of traitors in their subordinates (all direct and indirect subordinates excluding themselves) exceeds a threshold \( x \), then that person becomes a traitor immediately and all of their subordinates are also turned into traitors.

Your task is to find the minimum \( x \) (with \( 0 \le x \le 1 \)) such that in the worst-case scenario — that is, no matter which person is initially chosen as the traitor — the total number of traitors at the end does not exceed \( k \). Print \( x \) as a real number with 6 decimal places.

The process can be summarized as follows:

  1. Initially mark one person as a traitor.
  2. Repeatedly, for each person u who is not yet a traitor and has at least one subordinate, compute the traitor ratio \( r = \frac{T_u}{|\text{subordinates of u}|} \), where \( T_u \) is the number of already turned traitors among all subordinates of \( u \). If \( r > x \), then mark \( u \) and all nodes in the subtree rooted at \( u \) as traitors.

Determine and output the minimal \( x \) such that, regardless of which person is chosen initially, the final traitor count is at most \( k \>.

inputFormat

The first line contains two integers \( n \) and \( k \) — the number of people in the company and the maximum allowed number of traitors.

The next \( n-1 \) lines each contain an integer. For \( i = 2 \) to \( n \), the \( i\)th line gives the immediate superior (parent) of person \( i \) in the tree. Person 1 is the root.

outputFormat

Output a real number representing the minimum \( x \) such that in the worst-case scenario the number of traitors does not exceed \( k \). The answer should be printed with 6 decimal places.

sample

5 3
1
1
2
2
0.500000