#P8202. [传智杯 #4 决赛] [yLOI2021] 染色

[传智杯 #4 决赛] [yLOI2021] 染色

Background

Chuanzhi Cup 2021 Finals Problem G.

Problem Description

A teacher at Chuanzhi Specialization Academy assigned Xiaozhi a task.

The teacher gave Xiaozhi a sheet of paper with a tree of nn nodes drawn on it (if you do not know what a tree is, you can refer to the explanation in the previous problem). The teacher also gave Xiaozhi mm colored pens, each with a different color. The teacher wants Xiaozhi to color the nodes of the tree using these mm colors, so that the tree satisfies the following constraints:

  1. Each node is colored with exactly one of the mm colors.
  2. Any two adjacent nodes (if there is an edge directly connecting uu and vv, then we say uu and vv are adjacent) have different colors.
  3. The number of times any single color is used cannot exceed n3+1\lfloor\frac{n}{3}\rfloor + 1.

Note that although every node must be colored with some color, not every color has to be used.

This simple task is not difficult for Xiaozhi, so he raised a harder question: he wants to know how many coloring schemes satisfy the teacher's requirements. Xiaozhi cannot solve this, so he asks you for help. Please solve this problem for him.

Because the number of schemes may be very large, you only need to output the remainder when this number is divided by 998,244,353998,244,353. Two coloring schemes are different if and only if there exists a node uu such that the color of uu is different in the two schemes.

Input Format

The first line contains two integers, representing the number of nodes in the tree nn and the number of colors mm, respectively.
The next (n1)(n - 1) lines each contain two integers u,vu, v, indicating that there is an edge connecting uu and vv in the tree.

Output Format

Output one line with one integer, representing the remainder of the number of schemes modulo 998,244,353998,244,353.

4 4
1 2
1 3
3 4

108
3 3
1 2
1 3

12
5 5
1 2
1 3
2 4
3 5

1200
5 5
1 2
1 3
2 4
2 5
1140
7 8
1 2
1 3
2 4
2 5
3 6
3 7

929376
6 6
1 2
1 3
3 4
4 5
3 6
18750
10 20
1 2
1 3
2 4
2 5
2 6
2 7
3 8
5 9
9 10

688946281

Hint

Constraints

For all test points, it is guaranteed that 1u,vn1001 \leq u, v \leq n \leq 100, nm106n \leq m \leq 10^6, and the given graph is a tree.

Hint

Please pay attention to the impact of constant factors on program efficiency.

Translated by ChatGPT 5