QOJ.ac

QOJ

时间限制: 4 s 内存限制: 512 MB 总分: 100

#8670. Independent

统计

Given a tree with $n$ nodes and a positive integer $m$, the weight of each node is chosen independently and uniformly at random from $[1, m]$.

Calculate the expected value of the maximum independent set of this tree, multiplied by $m^n$.

The result should be taken modulo $998244353$.

The maximum independent set of a tree with node weights $a_{1\dots n}$ is defined as $\max\limits_{S\subseteq \{1,2,\cdots,n\}} \left(\sum\limits_{i\in S} a_i\right)$, where $S$ must satisfy the condition that no two nodes in $S$ are connected by an edge.

Input

The first line contains two positive integers $n$ and $m$.

The next $n-1$ lines each contain two positive integers, representing an edge of the tree.

Output

Output a single non-negative integer representing the answer.

Examples

Input 1

3 2
1 2
1 3

Output 1

24

Note

For example, when the node weights are $[2, 1, 1]$, the maximum independent set is $2$, which can be achieved by choosing $\{1\}$ or $\{2, 3\}$.

Subtasks

For all test cases, $1\le n\le 2000$ and $1\le m\le 10^8$.

  • Subtask 1 (11 pts): $n, m\le 5$.
  • Subtask 2 (24 pts): $n, m\le 20$.
  • Subtask 3 (13 pts): $n, m\le 500$.
  • Subtask 4 (27 pts): $n\le 500$.
  • Subtask 5 (25 pts): No additional constraints.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#855EditorialOpen题解alpha10222026-01-28 02:26:18View

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.