#P17340. 【MX-X30-T6】布谷鸟钟
【MX-X30-T6】布谷鸟钟
Background
You are right, but a certain four-character game is indeed fun.
Problem Description
You have a rooted tree with root .
At node , there is a non-negative integer and a positive integer . You may perform the following operation any number of times:
- Choose a node such that is not a multiple of . Then increase by for all nodes on the path from to the root (including both and the root).
After performing these operations, find the number of essentially different arrays , modulo .
Input Format
The first line contains an integer .
The next lines each contain two integers .
The next lines each contain two integers , indicating an edge.
Output Format
Output a single integer, representing the number of essentially different arrays modulo .
2
0 2
1 2
1 2
3
Hint
Let be the distance from the farthest node to the root.
| Subtask | Score | Constraints |
|---|---|---|
| 1 | ||
| 2 | , | |
| 3 | ||
| 4 | ,Special Property A | |
| 5 | ||
| 6 | None |
Special Property A: It is guaranteed that for , the parent of node in the rooted tree is generated uniformly at random from .
Constraints: For all testdata, , , .
Translated by ChatGPT 5