Codeforces Round 1093 (Div. 2)
E
Coloring a Red Black Tree
Codeforces
未评级
原题
← D2F →
翻译中…

You are given a tree of $n$ nodes numbered from 1 to $n$ and a binary string $s$ of length $n$ where $s_i = 1$ means that the $i$-th node is colored red and $s_i = 0$ means that the $i$-th node is colored black. You are allowed to perform the following operation:

翻译中…
  • Select a node $a$ ($1 \le a \le n$).
  • A neighbor $b$ of $a$ is selected uniformly at random.
  • Recolor node $a$ with the color of $b$. Note that this changes the color of the vertex you selected, not the one that was uniformly chosen.
翻译中…

You want to color all the nodes in the tree red by performing the operation any number of times (possibly zero). Please compute the minimum expected number of operations needed to do so if you perform them optimally. There will be at least one red node initially.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$).

翻译中…

The second line contains a binary string $s$ of size $n$.

翻译中…

The following $n-1$ lines each contain two integers, the $i$-th of them contains $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$), which means that there is an edge between nodes $u_i$ and $v_i$.

翻译中…

It is guaranteed that the given graph is a tree, there is at least one red node, and the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single real number representing the minimum expected number of operations.

翻译中…

Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$.

翻译中…

Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is accepted if and only if $\frac{|x - y|}{\max{(1, |y|)}} \le 10^{-6}$.

翻译中…

Note

翻译中…

In the first test case, there is only one node colored in black, which has only two red colored neighbors, thus, if we first apply the operation to the second node, we will have a red colored tree in just one operation.

翻译中…

样例

Input #1
3
3
101
1 2
2 3
5
10010
1 2
2 3
3 4
2 5
3
010
1 2
2 3
Output #1
1.00000000000000000000
4.50000000000000000000
2.00000000000000000000
InputCopy OutputCopy
题目信息
题号
2220E
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。