#P5425. Rikka with Tree II

Rikka with Tree II

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.

3 1 1
0.833333 Hint There are four ways to choose vertices: 1.choose {1,2}, then f=1,g=0. 2.choose {1,3}, then f=1,g=0. 3.choose {2,3}, then f=1,g=1. 4.choose {1,2,3}, then f=1,g=1.