当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5425:Rikka with Tree II

题目描述
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?
输入解释
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$.
输出解释
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.
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5425

最后修改于 2020-10-25T23:22:33+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)