#P10808. [LMXOI Round 2] Annihilation

    ID: 11876 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化莫比乌斯反演线段树合并

[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 nn nodes, rooted at 11, each node has a weight aia_i.

For a node uu, define the function f(u,v,d)f(u,v,d) as the number of ways to select some nodes (at least one node must be selected) within the subtree of uu, such that the maximum weight among the selected nodes is vv, and the greatest common divisor of their indices is dd.

Given a constant kk and a sequence bb, for each node uu, you need to compute the value of $\sum\limits_{k|i}^{n}\sum\limits_{j=1}^nf(u,i,j)\times b_j$, where kik|i means that kk divides ii. Since this value may be very large, output it modulo 998244353998244353.

Input Format

The first line contains two integers n,kn,k.

The next n1n-1 lines each contain two integers u,vu,v, indicating that there is an edge between uu and vv.

The next line contains nn numbers, where the ii-th number represents aia_i.

The next line contains nn numbers, where the ii-th number represents bib_i.

Output Format

Output one line with nn integers, where the uu-th integer (for u=1,2,nu=1,2,\ldots n) is the answer modulo 998244353998244353.

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 33 can choose {3}\{3\}. Since we are summing over maximum values that are multiples of 11, the contribution is 22.

Node 22 can choose {2},{3},{2,3}\{2\},\{3\},\{2,3\}. Since we are summing over maximum values that are multiples of 11, the contribution is 1+2+1=41+2+1=4.

Node 11 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 11, the contribution is 1+1+2+1+1+1+1=81+1+2+1+1+1+1=8.

For all testdata, 1ain1051 \le a_i\le n\le 10^5, 1bi1091\le b_i\le 10^9.

Subtask ID nn Special Property Score
Subtask #1 20\le 20 None 1010
Subtask #2 200\le 200
Subtask #3 2000\le 2000
Subtask #4 105\le 10^5 Random tree generation*
Subtask #5 k=1k=1 2020
Subtask #6 5×104\le 5\times 10^4 None
Subtask #7 105\le 10^5

Random tree generation*: for each node u=2,3,nu=2,3,\ldots n, its parent is chosen uniformly at random from the integers in [1,u1][1,u-1].

Translated by ChatGPT 5