#P6049. Counting Weighted Rooted Trees

    ID: 19273 Type: Default 1000ms 256MiB

Counting Weighted Rooted Trees

Counting Weighted Rooted Trees

You are given two positive integers n and m. A weighted rooted tree is defined on n labeled nodes (with labels from 1 to n) with the following properties:

  • The tree is rooted; that is, one vertex is designated as the root.
  • Each node has an integer weight in the range \( [1, m] \).
  • For every non‐root node, its weight does not exceed that of its parent. In other words, if vertex \(u\) is the parent of vertex \(v\) then \(w_u \ge w_v\).

Two weighted rooted trees are considered different if at least one of the following holds:

  • The number of nodes differs (this will not happen in this problem as every tree has exactly n nodes).
  • The choice of root differs.
  • There exists an index \(i\) such that the parent of node \(i\) is different in the two trees, or the weight of node \(i\) is different.

For example, when n = 2 the two possible rooted trees are 1 → 2 and 2 → 1. If the weight assignment for tree 1 → 2 is \(w_1=2, w_2=1\) then it is valid because \(2 \ge 1\). In tree 2 → 1, if \(w_2=2, w_1=1\) it is valid as well. Note that weight assignments are chosen independently provided the condition holds along every edge.

Your task is to count the number of weighted rooted trees (that is, a tree structure and an assignment of weights to the nodes satisfying the condition) modulo \(998244353\>.

Remark. It can be shown that if you fix a tree structure, then an assignment of weights is valid if for every vertex the weight assigned is at most the weight of its parent. In a rooted tree with \(n\) nodes, there are exactly \(n^{n-1}\) possible rooted trees and the weight‐assignments depend on the out–degrees. The answer may be very large so output it modulo \(998244353\).

inputFormat

The first line contains two integers n and m (1 ≤ n ≤ 7, 1 ≤ m ≤ 10), representing the number of nodes and the maximum weight value respectively.

Note: The limits have been chosen so that a brute force enumeration over all rooted trees is possible.

outputFormat

Output a single integer — the number of weighted rooted trees satisfying the conditions, taken modulo \(998244353\).

sample

2 2
6

</p>