QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 1024 MB Total points: 100

#9650. Chain Cover

Statistics

Background

A junior student asks you for help with the following problem:

  • Given a rooted tree with $n$ nodes, all nodes are initially white.
  • You can perform at most $k$ operations. In each operation, you select a node and paint all nodes on the simple path from that node to the root black.
  • Find the maximum number of nodes you can paint black. Solve this for each $k = 1 \sim n$.

This is certainly not a difficult problem. You explain the solution to the student, who marvels at the ingenuity of the approach and leaves satisfied.

Watching them walk away, you recall that two or three years ago, when you first learned how to solve this problem, you also marveled at its solution. But for you now, there is nothing magical about it; it is just a common routine.

However, well-known problems and conclusions are not necessarily boring or uninteresting. Thinking this, you record the problem:

Description

  • Given a rooted tree with $n$ nodes, all nodes are initially white.
  • You can perform at most $k$ operations. In each operation, you select a node and paint all nodes on the simple path from that node to the root black.
  • Find the maximum number of nodes you can paint black. Solve this for each $k = 1 \sim n$.

Let $ans(T, i)$ be the answer to the above problem for a labeled rooted tree $T$ when $k = i$.

Given $n$ and $\text{mod}$, for all $1 \le k \le n$ and $1 \le m \le n$, calculate how many different labeled rooted trees $T$ with $n$ nodes (rooted at $1$) satisfy $ans(T, k) = m$. The answer should be modulo $\text{mod}$.

Two labeled trees rooted at $1$ are considered different if and only if their edge sets are different.

Input

A single line containing two integers $n$ and $\text{mod}$.

Output

Output $n$ lines, each containing $n$ integers. The $m$-th integer in the $k$-th line represents the number of different labeled rooted trees $T$ with $n$ nodes (rooted at $1$) such that $ans(T, k) = m$, modulo $\text{mod}$.

Examples

Input 1

2 998244353

Output 1

0 1 
0 1

Input 2

3 998244353

Output 2

0 1 2 
0 0 3 
0 0 3

Input 3

4 998244353

Output 3

0 1 9 6 
0 0 1 15 
0 0 0 16 
0 0 0 16

Input 4

5 998244353

Output 4

0 1 40 60 24 
0 0 1 28 96 
0 0 0 1 124 
0 0 0 0 125 
0 0 0 0 125

Input 5

6 998244353

Output 5

0 1 195 560 420 120 
0 0 1 75 500 720 
0 0 0 1 75 1220 
0 0 0 0 1 1295 
0 0 0 0 0 1296 
0 0 0 0 0 1296

Constraints

This problem uses bundled testing. You must pass all test cases in a subtask to receive points for that subtask.

Subtask ID $n \le$ Score
$1$ $5$ $1$
$2$ $10$ $9$
$3$ $20$ $10$
$4$ $32$ $15$
$5$ $40$ $5$
$6$ $50$ $15$
$7$ $65$ $5$
$8$ $80$ $5$
$9$ $120$ $15$
$10$ $300$ $20$

For all data: $1 \le n \le 300$, $10^8 \le \text{mod} \le 1.05 \times 10^9$, and $\text{mod}$ is guaranteed to be a prime number.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.