F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Rikka with Tree II

Time 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
3 1 1
 

Sample Output
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.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 11:18:51, Gzip enabled