#P5443. [APIO2019] 桥梁

[APIO2019] 桥梁

Description

Saint Petersburg is located on nn islands connected by mm bridges. The islands are numbered with integers from 11 to nn, and the bridges are numbered with integers from 11 to mm. Each bridge connects two different islands. Some bridges were built in the era of Peter the Great, while others were built more recently. As a result, different bridges may have different weight limits. More specifically, only cars with weight not exceeding did_i can cross bridge ii. Sometimes, some bridges in Saint Petersburg are renovated, but this does not necessarily make their load capacity better; that is, after renovation, the did_i of a bridge may increase or decrease. You are going to develop a product to help citizens and city visitors. Currently, the module you are developing needs to support two types of operations:

  1. Change the weight limit of bridge bjb_j to rjr_j.

  2. Count how many different islands a car of weight wjw_j can reach starting from island sjs_j.

Please answer all queries of the second type.

Input Format

The first line contains two integers nn and mm, representing the number of islands and the number of bridges in Saint Petersburg.

The next mm lines each contain three integers ui,vi,diu_i, v_i, d_i. Line ii describes a bridge connecting islands uiu_i and viv_i, with an initial weight limit of did_i.

The next line contains one integer qq, representing the number of operations.

The next qq lines describe the operations in order, one per line.

The first integer on each line is tjt_j, indicating the operation type:

  • If tj=1t_j = 1, this is the first type of operation. The line then contains two integers bjb_j and rjr_j, meaning the weight limit of bridge bjb_j will become rjr_j.

  • If tj=2t_j = 2, this is the second type of operation. The line then contains two integers sjs_j and wjw_j, meaning a car of weight wjw_j will start from island sjs_j.

Output Format

For each query of the second type, output one line with one integer representing the answer.

3 4
1 2 5
2 3 2
3 1 4
2 3 8
5
2 1 5
1 4 1
2 2 5
1 1 1
2 3 2
3
2
3
7 8
1 2 5
1 6 5
2 3 5
2 7 5
3 4 5
4 5 5
5 6 5
6 7 5
12
2 1 6
1 1 1
2 1 2
1 2 3
2 2 2
1 5 2
1 3 1
2 2 4
2 4 2
1 8 1
2 1 1
2 1 3
1
7
7
5
7
7
4

Hint

For all testdata, 1n5×1041 \leq n \leq 5 \times 10^4, 0m1050 \leq m \leq 10^5, 1q1051 \leq q \leq 10^5. It is guaranteed that 1ui,vi,sjn1 \leq u_i, v_i, s_j \leq n, uiviu_i \neq v_i, 1di,rj,wj1091 \leq d_i, r_j, w_j \leq 10^9, 1bjm1 \leq b_j \leq m, and tj{1,2}t_j \in \{1, 2\}.

The detailed additional constraints and scores for the subtasks are shown in the table below.

Subtask Additional Constraints Score
1 n,m103n, m \leq 10^3, q104q \leq 10^4 13
2 The islands and bridges form a tree; m=n1m = n - 1, ui=iu_i = i, vi=i+1v_i = i + 1 (1im1 \leq i \leq m) 16
3 The islands and bridges form a complete binary tree; n=2k1n = 2^k - 1, m=n1m = n - 1, ui=i+12u_i = \frac{i+1}{2}, vi=i+1v_i = i + 1 (1k151 \leq k \leq 15, 1im1 \leq i \leq m) 17
4 All tit_i are 22 14
5 The islands and bridges form a tree 13
6 No special constraints 27

Translated by ChatGPT 5