Waterloo 2025 Fall A - Planting Trees

View as PDF

Submit solution


Points: 30
Time limit: 4.0s
Memory limit: 256M

Author:
Problem type

Alice and Ivan, having realized that owning a GPU farm is probably not the best for the environment, have decided to make up for their environmental transgressions by planting trees!

As Alice and Ivan are CS majors, they will not plant any old trees, but instead special unrooted trees with N nodes labelled 1, 2, \ldots, N, such that the degree of every node is an element of the set D = \{d_1, d_2, \ldots, d_M\}. Being very creative, they name these D-trees.

Alice and Ivan then plant a single mystery seed, which will sprout into any of the D-trees with equal probability. Being inquisitive, but also no longer having a GPU farm at their disposal, they task you to answer the following: for each i = 1, 2, \ldots, M, what is the expected number of nodes in their tree with degree d_i?

Input Specification

The first line of input will have two space-separated integers, N (2\leq N\leq 100\,000) and M (1\leq M < N).

The second line of input will have M space-separated integers, 1 = d_1 < d_2 < \cdots < d_M < N.

Output Specification

Output M space-separated integers on a single line, the ith of which should equal p_iq_i^{-1}\pmod{998244353}, where p_i/q_i is the expected number of nodes with degree d_i, as a fraction in lowest terms, i.e. \gcd(p_i,q_i) = 1.

It is guaranteed that the total number of D-trees is not a non-zero multiple of 998244353.

Sample Input 1

3 2
1 2

Sample Output 1

2 1

Explanation for Sample Output 1

There is a unique tree, up to relabeling, on 3 vertices whose nodes have degree 2. This is the tree with 2 nodes of degree 1, and 1 node of degree 2.

Sample Input 2

6 2
1 3

Sample Output 2

4 2

Sample Input 3

5 2
1 3

Sample Output 3

0 0

Explanation for Sample Output 3

There are no D-trees for D = \{1,3\}. Thus the expected number of nodes with degrees 1 and 3 is 0.


Comments

There are no comments at the moment.