luogu#P5237. 动态仙人掌 IV
动态仙人掌 IV
Background
Template problem.
Problem Description
There are vertices, numbered from . Vertex has a weight . Initially, there are no edges.
There are operations. An operation is considered valid if, after applying it, every connected component of this undirected graph is a cactus, and there are no self-loops. Otherwise, the operation is invalid. Invalid operations are ignored. There are six types of operations:
-
Add an edge of weight between vertices and .
-
Delete an edge of weight between vertices and .
-
Add to the weight of every vertex on the shortest path from vertex to vertex .
-
Add to the weight of every vertex in the sub-cactus , rooted at vertex .
-
Query information about the shortest path from vertex to vertex .
Output two integers separated by a space, representing the minimum vertex weight and the sum of vertex weights on the shortest path.
If there is no path reachable, then .
If the shortest path is not unique, then .
-
Query information about the sub-cactus , rooted at vertex .
Output two integers separated by a space, representing the minimum vertex weight and the sum of vertex weights in sub-cactus .
If and are not connected, then .
The definition of the sub-cactus rooted at vertex is: after deleting the edges on all simple paths between and , the connected component containing .
Input Format
The first line contains two positive integers separated by spaces, meaning there are vertices and operations in total.
The next line contains positive integers. The -th positive integer is .
The next lines each describe one operation. Each line starts with three integers: .
If , then one more integer follows; otherwise, the line ends.
Output Format
For operations and , output the corresponding results.
11 23
10 5 11 7 8 14 30 3 16 20 19
1 1 2 5
1 2 3 3
1 3 4 7
1 4 5 8
1 2 6 10
1 6 7 15
1 4 7 3
1 6 8 9
1 6 8 6
1 7 9 12
1 9 11 10
1 7 10 4
1 9 10 8
5 5 11
5 2 10
6 8 7
3 8 5 100
5 1 7
6 8 7
4 11 7 1000
5 8 3
4 3 2 2333
5 1 5
-2 -2
5 73
16 85
5 263
16 185
1005 4233
1011 9907
Hint
Constraints
For of the testdata, .
It is guaranteed that in operations and , satisfies , so computations involving edge weights will not exceed the range of a 32-bit signed integer.
It is guaranteed that the initial does not exceed , and that the sum of all in operations and does not exceed .
Translated by ChatGPT 5