#arc176f. F - Colorful Star
F - Colorful Star
Score: points
问题陈述
有一棵包含 个顶点的树,编号从 到 。第 条边()连接顶点 和 。
最初,顶点 被涂成颜色 。你可以执行以下操作零次或多次:
- 选择两个由边连接的顶点 和 。将顶点 的颜色重新涂成顶点 的颜色。
在操作后,找出可能的树的数量,对 取模。如果某个顶点的颜色不同,则区分两棵树。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a tree with vertices numbered to . The -th edge () connects vertices and .
Initially, vertex is colored with color . You can perform the following operation zero or more times:
- Choose two vertices and connected by an edge. Repaint the color of vertex with that of vertex .
Find the number, modulo , of possible trees after the operations. Two trees are distinguished if and only if some vertex has different colors.
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 1
Sample Output 1
42
One possible sequence of operations is as follows. Including this one, there are possible final trees.
Sample Input 2
4 2
Sample Output 2
219100
Sample Input 3
20 24
Sample Output 3
984288778
Sample Input 4
123456 112233
Sample Output 4
764098676