#P5443. [APIO2019] 桥梁
[APIO2019] 桥梁
Description
Saint Petersburg is located on islands connected by bridges. The islands are numbered with integers from to , and the bridges are numbered with integers from to . 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 can cross bridge . Sometimes, some bridges in Saint Petersburg are renovated, but this does not necessarily make their load capacity better; that is, after renovation, the 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:
-
Change the weight limit of bridge to .
-
Count how many different islands a car of weight can reach starting from island .
Please answer all queries of the second type.
Input Format
The first line contains two integers and , representing the number of islands and the number of bridges in Saint Petersburg.
The next lines each contain three integers . Line describes a bridge connecting islands and , with an initial weight limit of .
The next line contains one integer , representing the number of operations.
The next lines describe the operations in order, one per line.
The first integer on each line is , indicating the operation type:
-
If , this is the first type of operation. The line then contains two integers and , meaning the weight limit of bridge will become .
-
If , this is the second type of operation. The line then contains two integers and , meaning a car of weight will start from island .
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, , , . It is guaranteed that , , , , and .
The detailed additional constraints and scores for the subtasks are shown in the table below.
| Subtask | Additional Constraints | Score |
|---|---|---|
| 1 | , | 13 |
| 2 | The islands and bridges form a tree; , , () | 16 |
| 3 | The islands and bridges form a complete binary tree; , , , (, ) | 17 |
| 4 | All are | 14 |
| 5 | The islands and bridges form a tree | 13 |
| 6 | No special constraints | 27 |
Translated by ChatGPT 5
京公网安备 11011102002149号