#abc376g. G - Treasure Hunting
G - Treasure Hunting
Score : points
问题陈述
有一个根为 个顶点的树,顶点编号从 到 。顶点 是根,顶点 的父节点是顶点 。 在顶点 ,顶点 ,...,顶点 中,有一个顶点藏有宝藏。宝藏在顶点 的概率是 。同时,每个顶点都处于两种状态之一:“已搜索”和“未搜索”。最初,顶点 已搜索,所有其他顶点都是未搜索的。 在包含宝藏的顶点被搜索之前,你执行以下操作:
- 选择一个父节点已搜索的未搜索顶点,并将其标记为已搜索。
找到当你行动以最小化预期操作次数时所需的预期操作次数,模 。
你给出了 个测试用例;解决每一个。
如何找到模 的期望值
可以证明,期望值总是一个有理数。在这个问题的约束下,也可以证明,当期望值表示为不可约分数 时,我们有 。在这种情况下,有一个唯一的整数 满足 $R \times Q \equiv P \pmod{998244353},\ 0 \leq R < 998244353$。报告这个 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a rooted tree with vertices numbered from to . Vertex is the root, and the parent of vertex is vertex .
One of the vertices among vertex , vertex , ..., vertex hides a treasure. The probability that the treasure is at vertex is . Also, each vertex is in one of the two states: "searched" and "unsearched". Initially, vertex is searched, and all other vertices are unsearched.
Until the vertex containing the treasure becomes searched, you perform the following operation:
- Choose an unsearched vertex whose parent is searched, and mark it as searched.
Find the expected number of operations required when you act to minimize the expected number of operations, modulo .
You are given test cases; solve each of them.
How to find an expected value modulo
It can be proved that the expected value is always a rational number. Under the constraints of this problem, it can also be proved that when the expected value is expressed as an irreducible fraction , we have . In this case, there is a unique integer satisfying $R \times Q \equiv P \pmod{998244353},\ 0 \leq R < 998244353$. Report this .
Constraints
- The sum of over all test cases is at most .
- All input values are integers.
Input
The input is given from Standard Input in the following format. Here, denotes the -th test case.
Each test case is given in the following format:
Output
Print lines. The -th line should contain the answer for the -th test case.
Sample Input 1
3
3
0 0 1
1 2 3
5
0 1 0 0 0
8 6 5 1 7
10
0 1 1 3 3 1 4 7 5 4
43 39 79 48 92 90 76 30 16 30
Sample Output 1
166374061
295776107
680203339
In the first test case, the expected number of operations is .