#P10808. [LMXOI Round 2] Annihilation
[LMXOI Round 2] Annihilation
Background
While studying the previously rejected problem Impacter, LMX and HQZ came up with a new problem.
Problem Description
Given a rooted tree with nodes, rooted at , each node has a weight .
For a node , define the function as the number of ways to select some nodes (at least one node must be selected) within the subtree of , such that the maximum weight among the selected nodes is , and the greatest common divisor of their indices is .
Given a constant and a sequence , for each node , you need to compute the value of $\sum\limits_{k|i}^{n}\sum\limits_{j=1}^nf(u,i,j)\times b_j$, where means that divides . Since this value may be very large, output it modulo .
Input Format
The first line contains two integers .
The next lines each contain two integers , indicating that there is an edge between and .
The next line contains numbers, where the -th number represents .
The next line contains numbers, where the -th number represents .
Output Format
Output one line with integers, where the -th integer (for ) is the answer modulo .
3 1
1 2
2 3
1 1 2
1 1 2
8 4 2
4 1
1 2
2 4
1 3
1 1 2 1
1 2 3 1
19 5 3 1
10 3
1 2
1 3
2 4
2 5
3 6
3 7
7 8
5 9
9 10
1 3 7 3 6 6 6 9 4 8
450163553 649444963 324825063 696619525 758594756 594697697 750550965 907640826 118301481 755848673
475170649 914027313 64013204 696619525 210513956 594697697 111866638 907640826 0 0
Hint
Sample Explanation #1
Node can choose . Since we are summing over maximum values that are multiples of , the contribution is .
Node can choose . Since we are summing over maximum values that are multiples of , the contribution is .
Node can choose $\{1\},\{2\},\{3\},\{1,2\},\{1,3\},\{2,3\},\{1,2,3\}$. Since we are summing over maximum values that are multiples of , the contribution is .
For all testdata, , .
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| Subtask #1 | None | ||
| Subtask #2 | |||
| Subtask #3 | |||
| Subtask #4 | Random tree generation* | ||
| Subtask #5 | |||
| Subtask #6 | None | ||
| Subtask #7 |
Random tree generation*: for each node , its parent is chosen uniformly at random from the integers in .
Translated by ChatGPT 5