#P15336. [GCPC 2025] Island Urbanism

[GCPC 2025] Island Urbanism

Description

On a small volcanic island far away from any major landmass, the Grand Council for Painless Cycling (GCPC) is facing regular complaints about the bad quality of the bike path network. Their budget is limited, but they would like to improve the situation for all the cyclists on their island. A survey helped to determine the most common destinations of the cyclists. The GCPC expects that the cyclists are satisfied with the bike path replacements if there is a way to cycle between any two destinations using only newly replaced bike paths. In order not to unduly favour any of the villages, the Council has decided that a maximum of 77 destinations per village should be taken into account.

:::align{center}

Figure I.1: Illustration of the second sample. Village 1 consists of Junctions 1, 2, 3, and 4, Village 2 consists only of junction 5, and Village 3 consists of the remaining junctions. Junctions that are destinations are coloured red. :::

There is one main cyclic bike path going around the volcano. On its way, it traverses every village on the island exactly once. Each village may have additional bike paths. How much does the GCPC have to spend at least in order to replace bike paths to connect all destinations via new paths?

Input Format

The input consists of:

  • One line with four integers nn, mm, vv and kk (3n50003 \leq n \leq 5000, nm20000n \leq m \leq 20\,000, 3vn3 \leq v \leq n, 1kn1 \leq k \leq n), the number of junctions, the number of bike paths, the number of villages, and the number of destinations.
  • One line with vv integers uiu_i (1ui1 \leq u_i, i=1vui=n\sum_{i=1}^{v} u_i = n), the iith of which describes the number of junctions in village ii.
  • mm lines each containing three integers aa, bb and cc (1a,bn1 \leq a, b \leq n, 1c1091 \leq c \leq 10^9), describing a bidirectional bike path between junction aa and junction bb with a replacement cost of cc.
  • One line with kk distinct integers tt (1tn1 \leq t \leq n), the junctions that have to be connected by the replaced bike paths.

Additionally, the following is guaranteed:

  • Village 1 consists of junctions 1,,u11, \dots, u_1, village 2 consists of junctions u1+1,,u1+u2u_1 + 1, \dots, u_1 + u_2, and so on. The last village consists of junctions 1+i=1v1ui,,n1 + \sum_{i=1}^{v-1} u_i, \dots, n. Within each village, it is possible to travel between any pair of junctions without leaving the village.
  • There is a bike path between junctions i=1jui\sum_{i=1}^{j} u_i and 1+i=1jui1 + \sum_{i=1}^{j} u_i for each 1jv11 \leq j \leq v - 1, as well as a bike path between junctions nn and 11. There are no other bike paths between different villages.
  • There is at most one bike path between each pair of junctions and no bike path connects a junction to itself.
  • In each village there are at most 77 junctions that need to be part of the improved cycling network.

Output Format

Output the minimum cost which allows replacing bike paths such that every trip between any two destinations can be done using only newly replaced paths.

3 3 3 3
1 1 1
2 1 5
2 3 4
1 3 3
2 1 3
7
8 10 3 6
4 1 3
1 2 3
2 4 2
1 3 5
3 4 2
4 5 3
5 6 2
8 6 3
6 7 2
7 8 2
8 1 1
2 3 1 7 6 8
12