QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 512 MB 총점: 100
통계

Given $N$ and $V$, calculate the result of $\displaystyle\sum_{T \text{ is a labeled unrooted tree with } N \text{ vertices}} f(T)$ modulo $P$.

For a labeled unrooted tree $T$ with $N$ vertices, $f(T)$ is defined as the number of valid ways to assign weights to each vertex. Let $a_i$ be the weight of vertex $i$. An assignment is valid if and only if for all non-empty connected subgraphs $S$ of the tree, the following condition holds:

$$ \text{mex}(\{a_i \mid i \in S\}) = \min(\{a_i \mid i \notin S\}) $$

Here, $\text{mex}(E)$ is defined as the smallest non-negative integer not present in the set $E$, and $\min(E)$ is the minimum element in the set $E$. Specifically, $\text{mex}(\emptyset) = 0$ and $\min(\emptyset) = V + 1$.

Input

A single line containing three integers $N, V, P$.

Output

A single line containing the result of $\displaystyle\sum_{T \text{ is a labeled unrooted tree with } N \text{ vertices}} f(T)$ modulo $P$.

Examples

Input 1

5 3 998244353

Output 1

2280

Input 2, 3, 4

See the provided files.

Constraints

For all test cases, the following holds:

$$ 1 \leq N \leq 150, \quad 1 \leq V \leq 10^9, \quad 3 \leq P \leq 1.01 \times 10^9 $$

Subtask Score $N \leq$
$1$ $5$ $4$
$2$ $15$ $6$
$3$ $30$ $50$
$4$ $50$ $150$

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.