Under construction

Still being built. Things may change

Delivering Goods

Time limit5sMemory limit512 MB

Summary
Given a directed weighted graph and a set of client junctions, find the minimum number of trucks so each client is reached at its shortest-path time.
Level

Medium7 of 10

Topics
Graph, Shortest path, Dynamic programming, Minimum spanning tree
Solved
No attempts yet

Problem

You run a delivery company and have to send out trucks to bring goods to your clients. At the start of the day every package and every truck sits at your warehouse.

The road network consists of one-way streets between junctions. The warehouse and the clients are all at junctions, and you know the driving time of each street.

Your company guarantees extremely fast shipping. The trucks start driving the moment the day begins, and client ii receives the package at time TiT_i, where TiT_i is the shortest possible driving time from the warehouse to the junction of client ii.

What is the minimum number of trucks you have to deploy to keep that guarantee? That is, find the smallest number of trucks for which you can assign each truck a driving route so that every client ii is visited by some truck at time TiT_i. Loading a truck at the warehouse takes no time, and dropping goods off at a client takes no time once the truck arrives. The goods are small enough that a single truck can carry packages for as many clients as necessary.

Input

The input consists of a single test case.

The first line contains three integers NN, MM, and CC. Here NN is the number of junctions in the road network (2≤N≤1032 \le N \le 10^3), MM is the number of streets (1≤M≤1051 \le M \le 10^5), and CC is the number of clients (1≤C≤3001 \le C \le 300, C<NC < N).

The junctions are numbered 00 to N−1N-1, and the warehouse is always at junction 00. The second line contains CC distinct integers, the junctions where the clients reside. Each of them is between 11 and N−1N-1.

Each of the next MM lines contains integers UU, VV, WW (0≤U,V≤N−10 \le U, V \le N-1, U≠VU \ne V, 1≤W≤1091 \le W \le 10^9). This means there is a one-way street from UU to VV with driving time WW.

There is at most one street from a junction UU to another junction VV, but a street from UU to VV and a street from VV to UU may both exist. Every client is reachable from the warehouse.

Output

Print a single integer, the minimum number of trucks required so that every client ii is visited at time TiT_i by some truck.

Hint

In the first example one truck can follow the path (0,1,2)(0, 1, 2) and the other can follow (0,3)(0, 3). In the second example the only solution uses the three paths (0,1)(0, 1), (0,2)(0, 2), and (0,3)(0, 3). In the last example one truck follows (0,1)(0, 1), another follows (0,4,6)(0, 4, 6), and the last one follows (0,2,3,5,7)(0, 2, 3, 5, 7).

Examples3

  1. Example 1

    Input
    4 5 3
    1 2 3
    0 1 1
    0 3 1
    0 2 2
    1 2 1
    3 2 1
    
    Expected output
    2
    
  2. Example 2

    Input
    4 5 3
    1 2 3
    0 1 1
    0 3 1
    0 2 1
    1 2 1
    3 2 1
    
    Expected output
    3
    
  3. Example 3

    Input
    8 11 5
    1 3 4 6 7
    0 1 5
    0 4 1
    0 2 2
    0 6 6
    2 3 1
    2 6 3
    3 5 7
    4 1 5
    5 7 3
    6 5 6
    4 6 4
    
    Expected output
    3