Under construction

Still being built. Things may change

Building Shortcuts

Time limit3sMemory limit1024 MB

Summary
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 NN villages numbered from 1 to NN, and MM of them are central villages. Each village is connected to others by KK 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 AA to itself is 00. Village AA belongs to central village BB if the distance from AA to BB is smaller than the distance from AA 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:

  1. 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.
  2. 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 NN, MM, and KK. (2≤M≤N≤100 0002 \le M \le N \le 100\,000; N−1≤K≤200 000N-1 \le K \le 200\,000)

The second line contains MM integers, the numbers of the central villages, separated by spaces. The central village numbers are distinct.

Each of the next KK lines contains two village numbers uu and vv connected by a road and the road length ww, separated by spaces. (1≤u,v≤N1 \le u, v \le N; u≠vu \ne v; 1≤w≤1 000 000 0001 \le w \le 1\,000\,000\,000)

Output

Print the maximum number of shortcuts that the KITPA country approves when Jinheung requests as many shortcuts as possible under these conditions.

Examples2

  1. Example 1

    Input
    6 2 10
    2 4
    2 5 5
    4 2 8
    6 4 3
    2 6 9
    5 1 4
    2 3 4
    4 3 6
    1 4 6
    5 4 6
    6 3 7
    
    Expected output
    4
    
  2. Example 2

    Input
    8 2 20
    1 4
    4 7 7
    1 6 5
    4 1 1
    6 5 2
    8 2 2
    1 7 8
    5 4 1
    6 8 10
    6 7 6
    3 2 5
    4 6 1
    7 5 5
    3 4 4
    5 8 1
    4 8 5
    3 8 4
    7 8 5
    4 2 8
    1 2 4
    3 5 1
    
    Expected output
    3