#P4074. [WC2013] 糖果公园
[WC2013] 糖果公园
Description
Candyland has a Candy Park. Besides beautiful scenery and fun rides, there are many free candy distribution points, which attracts many candy-loving children to visit.
The structure of the Candy Park is peculiar. It consists of sightseeing spots, and each spot has a candy station. We number the spots from to . There are bidirectional roads connecting these spots, and the entire park is connected, meaning that starting from any spot, one can reach all other spots in the park via these roads.
There are types of candies in total, numbered from to . Each candy station only distributes a specific type of candy. We use to denote the candy type at spot .
Visitors do not like to retrace their steps. They always travel from a particular starting spot to a particular ending spot, visiting the spots along the way. This route is unique. When they pass each spot, they can taste one candy of the corresponding type.
People have different preferences for different types of candies. Based on visitor ratings, we obtained the tastiness index of candies: the tastiness index of the -th type of candy is . In addition, if a visitor repeatedly tastes the same type of candy, they will feel a bit bored. According to quantitative statistics, the novelty index for the -th time tasting a certain type of candy is . If a visitor tastes the -th type of candy for the -th time, their happiness index increases by the product of the corresponding tastiness index and novelty index, i.e., . The visitor’s final happiness index is the sum of these products.
Of course, the candy type distributed at each station may change from time to time (but always to one of the types), so that visitors can always feel surprised.
Staff member A received a task to compute each visitor’s happiness index based on recent park data. But A is not good at math and feels dizzy when seeing rows of numbers. As A’s best friend, you decide to help.
Input Format
The first line contains three positive integers , representing the number of spots, the number of candy types, and the number of operations.
The second line contains positive integers .
The third line contains positive integers .
From the 4th line to the -th line, each line contains two positive integers , indicating that there is a road directly connecting these two spots.
The -th line contains positive integers .
Then there are lines. Each line contains three integers , representing an operation:
- If is , then , , meaning that the candy type at spot is changed to .
- If is , then , meaning a query for the happiness index along the path from to .
Output Format
In the order of the input, for each operation with , output one line with a single positive integer representing the answer.
4 3 5
1 9 2
7 6 5 1
2 3
3 1
3 4
1 2 3 2
1 1 2
1 4 2
0 2 1
1 1 2
1 4 2
84
131
27
84
Hint
[Sample explanation]
We use

to denote nodes with equal to , , . Before modification:

After changing to :

[Constraints]
For all testdata: , , , and is a non-increasing sequence, i.e., for any , it holds that .
Other constraint conditions are as shown in the table below:

Translated by ChatGPT 5
京公网安备 11011102002149号