atcoder#ABC253H. [ABC253Ex] We Love Forest
[ABC253Ex] We Love Forest
Score : points
Problem Statement
We have a graph with vertices numbered through and edges. You are given sequences of length .
You will perform the following operation times.
- Choose uniformly at random. Add to an undirected edge connecting Vertices and .
Note that the operation above will add a new edge connecting Vertices and even if already has one or more edges between them. In other words, the resulting may contain multiple edges.
For each , find the probability, modulo , that is a forest after the -th operation.
What is a forest?
An undirected graph without a cycle is called a forest. A forest is not necessarily connected.
Definition of probability modulo $998244353$
We can prove that the sought probability is always a rational number. Moreover, under the Constraints of this problem, it is guaranteed that, when the sought probability is represented by an irreducible fraction , is indivisible by .
Then, we can uniquely determine an integer between and (inclusive) such that . Print this .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the probability, modulo , that is a forest after the -th operation.
3 2
1 2
2 3
1
499122177
Let us denote by the edge connecting Vertices and .
After the -st operation, will have:
- Edge with a probability of ;
- Edge with a probability of .
In both cases, is a forest, so the answer for is .
After the -nd operation, will have:
- Edges and with a probability of ;
- Edges and with a probability of ;
- Edges and with a probability of .
is a forest only when has Edges and . Therefore, the sought probability is ; when represented modulo , it is , which should be printed.
4 5
1 2
1 2
1 4
2 3
2 4
1
758665709
918384805