#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 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 colored pens, each with a different color. The teacher wants Xiaozhi to color the nodes of the tree using these colors, so that the tree satisfies the following constraints:
- Each node is colored with exactly one of the colors.
- Any two adjacent nodes (if there is an edge directly connecting and , then we say and are adjacent) have different colors.
- The number of times any single color is used cannot exceed .
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 . Two coloring schemes are different if and only if there exists a node such that the color of is different in the two schemes.
Input Format
The first line contains two integers, representing the number of nodes in the tree and the number of colors , respectively.
The next lines each contain two integers , indicating that there is an edge connecting and in the tree.
Output Format
Output one line with one integer, representing the remainder of the number of schemes modulo .
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 , , and the given graph is a tree.
Hint
Please pay attention to the impact of constant factors on program efficiency.
Translated by ChatGPT 5