Building Shortcuts
Time limit3sMemory limit1024 MB
Given a weighted road network with central villages, find the maximum number of new shortcuts between non-adjacent villages that keep each village's nearest center and distance unchanged.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Greedy, Sorting
- Solved
- No attempts yet
Problem
The KITPA country has villages numbered from 1 to , and of them are central villages. Each village is connected to others by bidirectional roads. Jinheung wants to build new shortcuts in the KITPA country to make travel between villages easier.
Each road has a given length. Every village can reach every other village using roads only. Two villages are connected by at most one road. The distance between two villages is the sum of the road lengths on the shortest path between them that uses roads only. The distance from village to itself is . Village belongs to central village if the distance from to is smaller than the distance from to every other central village.
Some villages may not belong to any central village.
Jinheung may pick two villages that have no road between them and request a shortcut between them. The KITPA country approves the shortcut only if its length is at most the smallest length among all roads directly connected to either of the two villages, measured before any shortcuts are built. Central villages watch each other's influence, so after the shortcuts are built, the following must hold:
- No village may belong to a different central village than it did before the shortcuts were built. A village that belongs to no central village may newly appear.
- The distance from each village to its nearest central village must be the same before and after the shortcuts are built.
Find the maximum number of shortcuts that the KITPA country approves when Jinheung requests as many shortcuts as possible under these conditions.
Input
The first line contains , , and . (; )
The second line contains integers, the numbers of the central villages, separated by spaces. The central village numbers are distinct.
Each of the next lines contains two village numbers and connected by a road and the road length , separated by spaces. (; ; )
Output
Print the maximum number of shortcuts that the KITPA country approves when Jinheung requests as many shortcuts as possible under these conditions.