#P17450. 同频回声 / Same Frequency Echo
同频回声 / Same Frequency Echo
Problem Description
You are given a weighted tree with nodes rooted at node .
Node has:
- frequency band ;
- transmission time .
Each frequency band has an importance value .
For two different nodes that use the same frequency band, define their synchronization cost as
where is the sum of edge weights on the simple path between and .
Each query provides a node and a non-negative integer .
We say that frequency band produces an echo in the region governed by if and only if there exist two different nodes
such that
Here, denotes the subtree rooted at .
For each query, compute the sum of importance values of all frequency bands that produce an echo:
$$\sum_{c=1}^{m} w_c \bigl[\exists\,u\ne v\in\operatorname{subtree}(x),\ c_u=c_v=c,\ D(u,v)\le K\bigr].$$The square brackets denote the Iverson bracket: it equals if the condition holds, and otherwise.
Input Format
The first line contains three integers (, , ), representing the number of nodes, the number of frequency bands, and the number of queries, respectively.
The second line contains integers (), representing the importance value of each frequency band.
The third line contains integers (), representing the frequency band used by each node.
The fourth line contains integers (), representing the transmission time of each node.
The next lines each contain three integers (, ), indicating an undirected edge between nodes and d$.
The next lines each contain two integers (, ), representing one query.
It is guaranteed that the edges form a tree, and that the answer fits in a signed -bit integer.
Output Format
For each query, output one integer per line, representing the answer.
7 3 5
5 7 11
1 2 1 3 2 1 3
10 4 13 8 9 20 7
1 2 2
1 3 3
2 4 4
2 5 1
3 6 2
3 7 5
1 5
1 6
2 6
3 9
1 15
0
12
7
5
23
Hint
The synchronization costs between nodes with the same frequency are as follows:
- Nodes on frequency band are : , , .
- Nodes on frequency band are : .
- Nodes on frequency band are : .
Therefore:
- In query , no frequency band produces an echo, so the answer is .
- In query , frequency bands produce echoes, so the answer is .
- In query , only frequency band produces an echo, so the answer is .
- In query , only frequency band produces an echo, so the answer is .
- In query , all three frequency bands produce echoes, so the answer is .
Translated by ChatGPT 5