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

建议使用的浏览器:

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

5946:Fxx and tree

题目描述
Young theoretical computer scientist Fxx has a tree.

You are given a rooted tree with n vertices,numbered from 1 to n(vertex 1 is the root).Each vertex of the tree has a value $A_i$ and a color,which is either black or white.

Now consider a reverse operation: Choose a vertex $X$ randomly.When X is chosen,its color changes.Meanwhile,the color of a vertex $K$ changes as well if and only if $X$ is an ancestor of $K$ and the distance between them is no more than $A_X$.

Fxx need to find out the expected number of operations to turn the whole tree black.Can you help him?
输入解释
In the first line, there is an integer $T(T\leq100)$ indicating the number of test cases.

For each test case,the first line contains one integers n(1\leq n\leq 50), indicating the number of vertice.

In the next n-1 lines, Each line contains two integers $u$ and $v$ meaning that vertice $u$ is the father of vertice $v$.

In the next line contains $n$ integers $A_1,A_2,\ldots,A_n(0\leq A_x\leq n)$.

In the next line contains $n$ integers $C_1,C_2,\ldots,C_n$, indicating the color of each vertice($C_x=0$ means the color of vertice $x$ is white, $C_x=1$ means the color of vertice $x$ is black)
输出解释
For each test case, output the answer.

Each answer is rounded to three decimal places.

For example,if the answer is "<b>3.7998</b>", you should output “3.800”.
输入样例
1
2
1 2
0 0
1 0
输出样例
3.000
来自杭电HDUOJ的附加信息
Recommend wange2014

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

题目来源 BestCoder Round #89

源链接: HDU-5946

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

共提交 0

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