luogu#P9161. Trees
Trees
Background
ZHY has many trees. Each tree has many nodes, and each node has a number on it, but he forgot what number was written on each node.
Problem Description
ZHY has trees. Every tree has the same shape and has nodes. Define as the -th node on the -th tree. You need to assign a value to every node , and it must satisfy the following conditions:
-
For all , we have .
-
For all , we have .
-
For any edge and , we have .
Please compute how many valid assignments there are, modulo . Note that these trees are ordered.
Input Format
The first line contains two positive integers .
The next lines each contain two positive integers , indicating that in each of the trees there is an undirected edge between and . It is guaranteed that the input forms a tree.
Output Format
Output one line containing the answer.
3 1
1 2
2 3
5
5 2
1 2
1 3
2 4
2 5
103
Hint
This problem uses bundled testdata.
For all testdata, , .
- Subtask 0 (10 pts): .
- Subtask 1 (30 pts): .
- Subtask 2 (15 pts): .
- Subtask 3 (25 pts): .
- Subtask 4 (20 pts): No special constraints.
Translated by ChatGPT 5