|
||||||||||
Rikka with Tree IITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 480 Accepted Submission(s): 149 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Now, Yuta has a tree with $n$ vertices. Let vertice 1 be the root and then for each vertice $i$ let $d_i$ be the distance between 1 and $i$. Then Yuta wants to choose out at least two vertieces. It is clear that there have $2^n-n-1$ ways to choose. He will choose one of them equiprobable. Then let $f$ be the largest $d_i$ and $g$ be the second largest $d_i$ of the chosen vertices.($f$ may be equal to $g$) Yuta wants to know the expected value of $\frac{(f+1)(g+1)}{f+1+g+1}$. It is too difficult for Rikka. Can you help her? Input There are no more than 100 testcases and there are no more than 3 testcases with $n \geq 1000$ For each testcase, the first line contains a number $n(2 \leq n \leq 10^5)$. Then the second line contains $n-1$ numbers $f_i (1 \leq f_i \leq i)$, means the father of vertice $i+1$. Output For each testcase, print a single number. You only need to reserve six decimal places. Sample Input
Sample Output
Source | ||||||||||
|