#P10359. [PA 2024] Kolorowy las
[PA 2024] Kolorowy las
Background
PA 2024 4A
Problem Description
This problem is translated from PA 2024 Round 4 Kolorowy las. Thanks to Macaronlin for providing the translation.
You are given a forest with vertices (an undirected acyclic graph). The vertices are numbered from to . Each edge has a positive integer weight. Each vertex has a color, and initially all vertex colors are .
There are operations of types:
- : Add an edge of weight between and (it is guaranteed that the graph is still acyclic after adding the edge).
- : Delete the edge between and .
- : Recolor all vertices that are reachable from and whose distance to is at most to color .
- : Query the color of vertex .
Input Format
The first line contains three integers $n,m,q\ (2\le n\le 200\,000,0\le m\le n-1,1\le q\le 200\,000)$, representing the number of vertices, the number of edges, and the number of operations.
The next lines each contain three integers , indicating that there is an edge of length between vertices and .
The next lines describe the operations in the format given in the description. It is guaranteed that , , , and .
It is guaranteed that the given edges form a valid forest, and after all modifications the graph still forms a valid forest. It is also guaranteed that no operation deletes an edge that does not exist in the graph.
In addition, it is guaranteed that there is at least one operation of type .
Output Format
For each operation of type , output one line with one integer, the answer.
4 2 9
1 2 2
3 2 5
4 2
3 2 2 5
4 1
3 2 4 3
4 1
4 3
2 2 1
1 1 4 1
4 4
0
5
3
0
0
Hint
- In some subtasks, there are no operations of type and , and .
- In some subtasks, all operations of type satisfy .
For each of the additional constraints above, there is at least one subtask that satisfies it. The sets of subtasks satisfying the two additional constraints may overlap or may be disjoint.
Translated by ChatGPT 5