#P4172. [WC2006] 水管局长

    ID: 3098 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>图论2006平衡树WC/CTSC/集训队O2优化生成树最近公共祖先,LCALink-Cut Tree,LCT

[WC2006] 水管局长

Description

Each day, the water supply company may need to deliver a certain amount of water from uu to vv. Dudu must find a path of pipes from uu to vv for the company. Then, through an information control center, he instructs the pipes on the path to enter a ready-to-deliver state. Once every pipe on the path is ready, the company can start delivering water. Dudu can handle only one delivery task at a time; he can process the next task only after the current delivery is completed.

Before each delivery task, every pipe on the chosen path must undergo a series of preparation operations, such as cleaning and disinfection. At Dudu’s command, these preparations start simultaneously on all pipes of the path. However, due to differences in length and inner diameter, the required preparation time may vary from pipe to pipe.

The water supply company always hopes Dudu can find a delivery path such that the time until all pipes on the path are ready is as short as possible. Dudu wants you to help him build a system that selects such a path to meet the company’s requirement. In addition, since the water pipes in MY City are old, some pipes may occasionally fail and become unusable; your program must take this into account.

We model the water pipe network of MY City as a simple undirected graph (i.e., without self-loops or multiple edges): pipes are edges, and junctions are nodes. The entire graph has nn nodes and mm edges, with nodes numbered from 11 to nn.

Input Format

The first line contains three integers, representing the number of junctions (nodes) nn, the current number of pipes (undirected edges) mm, and the number of tasks your program needs to process (including both finding a path that meets the requirement and accepting that some pipe has broken) qq.

Each of the next mm lines contains three integers u,v,tu, v, t, indicating there is a pipe connecting (u,v)(u, v) with preparation time tt.

Each of the next qq lines contains three integers k,u,vk, u, v, describing a task. Here kk indicates the task type:

  • If k=1k = 1, you need to find a path of pipes from uu to vv that meets the requirement, i.e., the preparation time is minimized.
  • If k=2k = 2, it means the pipe directly connecting uu and vv is declared scrapped.

Output Format

For each task with k=1k = 1, output a single integer on one line indicating the answer.

4 4 3
1 2 2
2 3 3
3 4 2
1 4 2
1 1 4
2 1 4
1 1 4

2
3

Hint

Constraints

For all test points, it is guaranteed that:

  • 1n1031 \leq n \leq 10^3, 1m,q1051 \leq m, q \leq 10^5.
  • 1k21 \leq k \leq 2, 1u,vn1 \leq u, v \leq n, 1t1091 \leq t \leq 10^9.
  • The given graph has no multiple edges and no self-loops. Before a pipe is declared scrapped, it is guaranteed that the pipe exists in the graph and has not been scrapped.
  • The number of scrapped pipes does not exceed 5×1035 \times 10^3, and at any time the graph is guaranteed to remain connected.

Translated by ChatGPT 5