#P5478. [BJOI2015] 骑士的旅行

[BJOI2015] 骑士的旅行

Description

According to Henry’s investigation, there are a total of MM titled knights on the continent, numbered from 11 to MM. The ii-th knight lives in city PiP_i and has combat power FiF_i.

Henry plans to make several journeys. In each journey, he starts from some city and travels along the unique simple path to another city, and he will challenge the strongest KK knights (Henry has limited stamina, and to improve himself, of course he challenges the strongest knights). If there are fewer than KK knights on the route, Henry will challenge everyone he meets.

Before each journey, some knights’ combat power or residence may change. Henry will naturally gather information and adjust his plan.

To be fully prepared for each journey, Henry wants you to help compute which opponents he will challenge on that route before each journey.

Input Format

The first line contains an integer NN, meaning there are NN cities, numbered from 11 to NN.

The next N1N-1 lines each contain two integers uiu_i and viv_i, indicating that there is a road between city uiu_i and city viv_i.

Line N+1N+1 contains an integer MM, meaning there are MM knights.

The next MM lines each contain two integers FiF_i and PiP_i, describing in order the combat power and residence of each knight numbered from 11 to MM.

Line N+M+2N+M+2 contains two integers QQ and KK, meaning the number of operations and the maximum number of knights challenged in each journey.

The next QQ lines each contain three integers TiT_i, XiX_i, and YiY_i. Ti{1, 2, 3}T_i \in \{1,~2,~3\} indicates the operation type.

There are three types of operations:

When Ti=1T_i=1, it means a journey: Henry will travel from city XiX_i to city YiY_i.

When Ti=2T_i=2, it means the residence of knight XiX_i is moved to city YiY_i.

When Ti=3T_i=3, it means the combat power of knight XiX_i is changed to YiY_i.

Output Format

Output several lines, in order, as the answers for each journey.

For each query with Ti=1T_i=1, output one line listing, in decreasing order, the combat power values of all knights Henry challenges in this journey. If there are no knights on the route, output one line containing the integer 1-1.

5  
1 2  
1 3  
2 4  
2 5  
4  
10 1  
6 1  
14 5  
7 3  
5 3  
1 2 3  
1 5 3  
1 4 4  
2 1 4  
1 2 3
10 7 6  
14 10 7  
-1  
7 6

Hint

Constraints: for 100%100\% of the testdata, 1N, M40,0001 \leq N,~M \leq 40,000, 1Ui, Vi, PiN1 \leq Ui,~Vi,~Pi \leq N, 1Q80,0001 \leq Q \leq 80,000, 1K201 \leq K \leq 20. The number of journeys does not exceed 40,000. Combat power values are positive integers not exceeding 1,000.

Translated by ChatGPT 5