#P2095. Path Killer
Path Killer
题目描述
点击查看pdf
MainKing has a rooted tree with nodes, and paths on it. And the root of this tree is .
The endpoints of the i-th path are . All of these paths satisfy a special condition: is on the path from to the root.
Now MianKing wants to delete all of these paths. He will do the following operator until all of the paths are deleted: choose an integer from randomly and delete all of the paths where is on.
MianKing wants you to calculate the expected number of operations he need to do.
It's guaranteed that the answer will converge to some rational number.
If the answer is irreducible fraction , you need to output an integer in which satisfies . It's guaranteed that
输入格式
The first line has two integers .
The second line has integers, the i-th integer denotes the father node of node
Then there are lines, the i-th line has two integers .
Let denote the father node of node . Then for
. It's guaranteed that is on the path from to the root.
输出格式
Output the answer.
样例
3 3
1 1
1 2
3 3
1 1
499122181
提示
Form 2020ICPC济南站