#P5680. [GZOI2017] 共享单车
[GZOI2017] 共享单车
Background
GZOI2017 D2T3
Problem Description
There are two shared bicycle companies, Company A and Company B, competing on a campus. To increase its market share on campus as much as possible, Company A will try to interfere with Company B’s recycling operations.
The whole campus consists of areas and roads, where each road connects two areas. There is an area that is Company B’s base. All recycling operations start from this area. To reduce costs, when recycling, for going from area to any area , Company B always chooses a shortest path. If there are multiple shortest paths to some area, it chooses, among all shortest paths, the one whose previous area on the path has the smallest index. This path is called the recycling route from to . All recycling routes form a tree structure, called the recycling route tree. In the figure below, the green edges form a recycling route tree.

Each time, Company B recycles bicycles from several areas; these areas are called recycling areas. Company B also designates some areas as deployment areas, and the remaining areas are called non-deployment areas. On the recycling route tree, mark area , mark all recycling areas, and also mark the lowest common ancestor on the recycling route tree of any two recycling areas.
In the figure below, suppose areas and are deployment areas, and areas are recycling areas. Then the marked areas are .

Company A interferes with Company B’s recycling operation if and only if for every marked deployment area other than , on the recycling route from area to , there exist two marked areas such that all roads (the path between the two nodes on the recycling route tree) between them are blocked.
The cost to block a road is the length of that road. In the figure above, Company A chooses to block the two paths and , and the cost is .
Your task is to help Company A compute how to block Company B’s recycling operation with the minimum total cost.
Input Format
The first line contains four integers , representing the number of areas on campus, the number of roads, the index of Company B’s base, and the number of operations.
Lines to describe the roads. Each line contains three integers , meaning there is an undirected road of length between and .
Then, lines to describe the operations. The first integer of each line indicates the operation type: means Company B changes the deployment areas, and means one recycling operation by Company B.
For an operation of type , it is followed by an integer , meaning the number of areas to be changed, and then integers giving the area indices. For each changed area, if it is a deployment area, change it to a non-deployment area; if it is a non-deployment area, change it to a deployment area.
For an operation of type , it is followed by an integer , meaning the number of recycling areas, and then integers giving the indices of Company B’s recycling areas. Each time, you need to remark nodes on the recycling route tree.
Output Format
For each recycling operation, output one line with the minimum cost for Company A to interfere with Company B. Note that if there is no marked deployment area, output .
6 6 1 4
1 2 3
2 3 2
2 4 4
3 6 4
1 5 5
5 6 3
0 3 3 4 6
1 3 4 5 6
0 1 3
1 4 3 4 5 6
10
6
12 11 4 5
4 1 32
4 6 42
1 3 29
7 1 17
7 10 23
9 7 21
5 6 16
2 6 28
5 8 14
8 11 11
8 12 17
1 11 1 2 3 5 6 7 8 9 10 11 12
0 4 3 11 5 2
1 4 10 9 6 11
0 4 7 8 12 11
1 4 11 2 9 10
-1
41
77
Hint
【Constraints】
For of the testdata, , .
For of the testdata, it is guaranteed that in each operation, the number of recycling areas is always .
For of the testdata, , , , .
For of the testdata, , , , .
All testdata guarantee that there are no self-loops. All road lengths are less than , and area is never a deployment area at any time.
Translated by ChatGPT 5