atcoder#ARC150D. [ARC150D] Removing Gacha
[ARC150D] Removing Gacha
Score : points
Problem Statement
We have a rooted tree with vertices numbered to . Vertex is the root of the tree, and the parent of vertex is vertex .
Each vertex has a color: black or white. Initially, all vertices are white.
In this rooted tree, vertex is said to be good when all vertices on the simple path connecting vertices and (including vertices and ) are black, and bad otherwise.
Until all vertices are black, let us repeat the following operation: choose one vertex from the bad vertices uniformly at random, and repaint the chosen vertex black.
Find the expected value of the number of times we perform the operation, modulo .
The definition of the expected value modulo $998244353$
It can be proved that the sought expected value is always a rational number. Additionally, when that value is represented as an irreducible fraction , it can also be proved that . Therefore, there is a unique integer such that and . Find this .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
4
1 1 3
831870300
Consider a case where the first three operations have chosen vertices , , and in this order. Then, vertices and are good, but vertex is still bad since vertex , an ancestor of vertex , is white. Thus, the fourth operation will choose vertex or uniformly at random.
The expected value of the number of times we perform the operation is .
15
1 2 1 1 4 5 3 3 5 10 3 6 3 13
515759610