#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 nn vertices (an undirected acyclic graph). The vertices are numbered from 11 to nn. Each edge has a positive integer weight. Each vertex has a color, and initially all vertex colors are 00.

There are qq operations of 44 types:

  • 1 ai bi di1\ a_i\ b_i\ d_i: Add an edge of weight did_i between aia_i and bib_i (it is guaranteed that the graph is still acyclic after adding the edge).
  • 2 ai bi2\ a_i\ b_i: Delete the edge between aia_i and bib_i.
  • 3 vi zi ki3\ v_i\ z_i\ k_i: Recolor all vertices that are reachable from viv_i and whose distance to viv_i is at most ziz_i to color kik_i.
  • 4 ui4\ u_i: Query the color of vertex uiu_i.

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 mm lines each contain three integers ai,bi,di (1ai,bin,1di109)a_i,b_i,d_i\ (1\le a_i,b_i\le n,1\le d_i\le 10^9), indicating that there is an edge of length did_i between vertices aia_i and bib_i.

The next qq lines describe the operations in the format given in the description. It is guaranteed that 1ai,bi,vi,uin1\le a_i,b_i,v_i,u_i\le n, 1di1091\le d_i\le 10^9, 0zi10150\le z_i\le 10^{15}, and 1ki1091\le k_i\le 10^9.

It is guaranteed that the given mm 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 44.

Output Format

For each operation of type 44, 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 11 and 22, and m=n1m=n-1.
  • In some subtasks, all operations of type 33 satisfy zi=1015z_i=10^{15}.

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