AtCoder Grand Contest 069
D
Tree and Intervals
AtCoder
⌀ 3346
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given an integer $N$ and a prime $P$.

翻译中…

For a tree with $N$ vertices labeled $1$ through $N$, let $a_i$ and $b_i$ be the endpoints of the $i$-th edge $(1 \leq i \leq N-1)$. Also, define $x_j\ (1 \leq j \leq N-1)$ as:

翻译中…
  • The number of integers $i\ (1 \leq i \leq N-1)$ satisfying $\min(a_i,b_i) \leq j \lt \max(a_i,b_i)$.
翻译中…

Find the number, modulo $P$, of sequences that could be $(x_1, x_2, \ldots, x_{N - 1})$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 500$
  • $10^8 \leq P \leq 10^9$
  • $P$ is prime.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N P

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3 998244353
Output #1
3
There are three different trees with three vertices, if we distinguish the vertices by their labels but not the edges. The corresponding $(x_1, x_2)$ are $(1, 1)$, $(2, 1)$, and $(1, 2)$, so the expected output is $3$ modulo $P = 998244353$.
Input #2
69 433416647
Output #2
243082757
Find the count modulo $P$.
题目信息
题号
agc069_d
时间限制
4.5 s
内存限制
2048 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。