#P14857. [ICPC 2021 Yokohama R] Planning Railroad Discontinuation

[ICPC 2021 Yokohama R] Planning Railroad Discontinuation

题目描述

The ICPC Kingdom has a large round lake in its center, and all of its cities are developed around the lake, forming a circle of cities. Because all of them are developed under the same urban plan, the cities are made quite similar. They have exactly the same subway networks. Some of their stations are also stations of inter-city bullet trains connecting two corresponding stations of adjacent cities. All of the train routes provide two-way traffic between two terminal stations without any intermediate stations.

The cities have the same number of subway stations and subway routes. In each city, the stations are numbered sequentially as 0,1,2,0, 1, 2, \dots. Whether two stations in a city are connected by a subway route depends only on their station numbers and not on the city. If a station vv is connected to a station uu in one city, so is in all the other cities. The travel distance between two stations vv and uu are the same for all the cities.

All the cities have exactly the same list of station numbers of bullet train stations. If a station ss is a bullet train station in one city, so is in all the other cities. All the pairs of two bullet train stations of the same station number in two adjacent cities are connected by a bullet train route. If a station ss is one end of a bullet train route, the station ss in an adjacent city is the other end. There exist no other bullet train routes. One can travel between any two stations in the Kingdom via one or more subway and/or bullet train services.

Due to financial difficulties in recent years, the Kingdom plans to discontinue some of the subway and bullet train services to reduce the maintenance cost of the railroad system. The maintenance cost is the sum of maintenance costs of the subway routes and the bullet train routes. The maintenance cost of a subway route is the sum of base cost depending on the city and cost proportional to the travel distance of the route. The maintenance cost of a bullet train route depends only on the two cities connected by the route.

You are asked to make a plan to discontinue some of the routes that minimizes the total maintenance cost. Of course, all the pairs of the stations in the Kingdom should still be connected through one or more subway and/or bullet train services after the discontinuation.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} &n\ m \\ &v_1\ u_1\ d_1 \\ &\vdots \\ &v_m\ u_m\ d_m \\ &l \\ &a_0\ b_0 \\ &\vdots \\ &a_{l-1}\ b_{l-1} \\ &r \\ &s_1 \\ &\vdots \\ &s_r \end{aligned}$$

Here, nn is an integer satisfying 2n1042 \leq n \leq 10^4, which is the number of the subway stations in a city. The stations in each city are numbered from 00 to n1n-1. mm is an integer satisfying 1m1051 \leq m \leq 10^5, which is the number of the subway routes in a city. The following mm lines are information on the subway system in a city. The ii-th of the mm lines has three integers viv_i, uiu_i, and did_i, satisfying 0vi<n0 \leq v_i < n, 0ui<n0 \leq u_i < n, viuiv_i \ne u_i, and 1di1091 \leq d_i \leq 10^9. They mean that a subway route connects stations numbered viv_i and uiu_i, and its maintenance cost proportional to the travel distance is did_i. There is at most one subway route between two stations. All the subway stations in a city are connected directly or indirectly via one or more subway routes.

ll in the next line is an integer satisfying 3l1053 \leq l \leq 10^5, which is the number of cities in the Kingdom. The cities are numbered from 00 to l1l-1, and the city 00 is also called the city ll. For each 0jl10 \leq j \leq l-1, the cities jj and j+1j+1 are adjacent. aja_j and bjb_j in the following ll lines are integers satisfying 1aj1091 \leq a_j \leq 10^9 and 1bj1091 \leq b_j \leq 10^9. aja_j is the maintenance cost of a bullet train route connecting the cities jj and j+1j+1. bjb_j is the base cost of the subway routes in the city jj.

rr is an integer satisfying 1rn1 \leq r \leq n, which is the number of the bullet train stations in each city. s1,s2,,srs_1, s_2, \dots, s_r are the station numbers of the bullet train stations in each city.

输出格式

Output in a single line the integer representing the minimum maintenance cost of the railroad system after the discontinuation that minimizes the cost while keeping all the stations connected, directly or indirectly.

2 1
0 1 3
3
6 1
4 2
5 3
1
1
24
3 3
0 1 7
1 2 8
2 0 5
4
8 1
5 1
9 3
7 3
2
1
2
76
5 8
0 1 1
2 1 2
4 0 5
3 4 7
3 2 8
0 2 4
4 1 3
2 4 6
6
3 2
9 3
7 1
5 3
3 2
5 2
4
0
2
3
4
120