#P8329. [ZJOI2022] 树

    ID: 9392 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>各省省选2022浙江O2优化容斥原理

[ZJOI2022] 树

Background

The annual ZJOI is about to be held again, but the veteran problem setter Kujou Karen suddenly had an urgent matter and had to return to the UK.

“Leave it to you all! There will definitely be no problem desu!”, after saying that, Karen ran off into the distance.

Shinobu, Alice, Aya, and Youko watched Karen leave and felt a bit at a loss. After all, there were less than three weeks left until ZJOI.

“Since this is the task Karen-chan left behind, we must work hard to finish it. After all, I am the older sister,” said Alice.

So everyone began setting problems enthusiastically. “Hopefully this is the first and also the last time,” everyone thought in unison.

At the same time, the main character of the problem was set to be Kujou Karen!

Problem Description

Kujou Karen is a girl who likes trees. She wants to generate two trees, each with nn nodes.

The first tree is generated as follows:

  1. Node 11 is the root of the tree.
  2. For i[2,n]i \in [2, n], choose a node from [1,i1][1, i - 1] as the parent of ii.

The second tree is generated as follows:

  1. Node nn is the root of the tree.
  2. For i[1,n1]i \in [1, n - 1], choose a node from [i+1,n][i + 1, n] as the parent of ii.

Kujou Karen wants that for any i[1,n]i \in [1, n]: if node ii is a leaf in the first tree, then node ii is a non-leaf in the second tree; if node ii is a non-leaf in the first tree, then node ii is a leaf in the second tree. A node is called a leaf if and only if no node has it as its parent.

Kujou Karen wants you to count the number of ways to generate the two trees. Specifically, you need to compute the number of ways for all n[2,N]n \in [2, N]. Two ways are different if and only if there exists a node ii in one of the trees whose parent is different in the two ways. Since the answer may be very large, you only need to output the result modulo MM.

Input Format

The first line contains two integers N,MN, M, representing the upper limit on the number of nodes in the tree and the modulus.

Output Format

Output N1N - 1 lines, each containing one integer.

Specifically, on the ii-th line output the value of the answer modulo MM when n=i+1n = i + 1.

5 998244353

1
2
12
120

见附件中的 tree/tree_ex2.in
见附件中的 tree/tree_ex2.ans

Hint

For all test cases: it is guaranteed that 2N5002 \le N \le 500 and 10M23010 \le M \le 2^{30}.

The specific limits for each test case are shown in the table below:

Test Case ID NN \le Special Constraints
11 1010 None
22 2020 Guaranteed that MM is prime
33 5050 None
44 Guaranteed that MM is prime
55 100100 None
66 Guaranteed that MM is prime
77 500500 None
88 Guaranteed that MM is prime
99 None
1010 Guaranteed that MM is prime

Translated by ChatGPT 5