#P7617. [2018年杭电多校]Traffic Network in Numazu
[2018年杭电多校]Traffic Network in Numazu
Traffic Network in Numazu
Problem Description
Chika is elected mayor of Numazu. She needs to manage the traffic in this city. To manage the traffic is too hard for her. So she needs your help.
You are given the map of the city --- an undirected connected weighted graph with nodes and edges, and you have to finish missions. Each mission consists of integers , and .
When , you need to modify the weight of the edge to .
When , you need to calculate the length of the shortest path from node to node .
Input
The first line contains a single integer , the number of test cases.
Each test case starts with a line containing two integers and , the number of nodes (and edges) and the number of queries.
Each of the following lines contain the description of the edges. The line represents the edge, which contains space-separated integers , , and . This means that there is an undirected edge between nodes and , with a weight of .
Then lines follow, the line contains integers , and . The meaning has been described above.$(0 \leq OP \leq 1) (1 \leq X \leq 10^5) (1 \leq Y \leq 10^5)$
It is guaranteed that the graph contains no self loops or multiple edges.
Output
For each test case, and for each mission whose , print one line containing one integer, the length of the shortest path between and .
Sample Input
2
5 5
1 2 3
2 3 5
2 4 5
2 5 1
4 3 3
0 1 5
1 3 2
1 5 4
0 5 4
1 5 1
5 3
1 2 3
1 3 2
3 4 4
4 5 5
2 5 5
0 1 3
0 4 1
1 1 4
Sample Output
5
6
6
6
Source
2018 Multi-University Training Contest 7