luogu#P4949. 最短距离

    ID: 3958 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>最近公共祖先 LCA树链剖分基环树

最短距离

Problem Description

You are given an undirected connected graph with nn vertices and nn edges.

You need to support two types of operations:

  1. Modify the length of the xx-th edge to yy.
  2. Query the shortest distance from vertex xx to vertex yy.

There are mm operations in total.

Input Format

The input has a total of n+m+1n+m+1 lines:

Line 11 contains two positive integers n,mn,m, representing the number of vertices (which is also the number of edges) and the number of operations.

Lines 22 to n+1n+1 each contain three positive integers x,y,zx,y,z, indicating that there is an edge of length zz between xx and yy.

Lines n+2n+2 to n+m+1n+m+1 each contain three positive integers opt,x,yopt,x,y, representing the type of operation and its parameters (see the meaning in the “Description”).

Output Format

For each operation of type 22, output the query result.

4 5
1 2 11
1 3 12
2 3 13
1 4 15
2 2 3
1 2 1
2 2 3
2 2 4
2 3 4
13
12
26
16

Hint

Luogu

For 100%100\% of the testdata, it is guaranteed that z[0,5000]z\in [0,5000].

Translated by ChatGPT 5