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.
Medium7GraphShortest pathDynamic programmingMinimum spanning treeNo attempts yetTime limit5sMemory limit512 MBYou 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 i receives the package at time Ti, where Ti is the shortest possible driving time from the warehouse to the junction of client i.
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 i is visited by some truck at time Ti. 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.
The input consists of a single test case.
The first line contains three integers N, M, and C. Here N is the number of junctions in the road network (2≤N≤103), M is the number of streets (1≤M≤105), and C is the number of clients (1≤C≤300, C<N).
The junctions are numbered 0 to N−1, and the warehouse is always at junction 0. The second line contains C distinct integers, the junctions where the clients reside. Each of them is between 1 and N−1.
Each of the next M lines contains integers U, V, W (0≤U,V≤N−1, U=V, 1≤W≤109). This means there is a one-way street from U to V with driving time W.
There is at most one street from a junction U to another junction V, but a street from U to V and a street from V to U may both exist. Every client is reachable from the warehouse.
Print a single integer, the minimum number of trucks required so that every client i is visited at time Ti by some truck.
In the first example one truck can follow the path (0,1,2) and the other can follow (0,3). In the second example the only solution uses the three paths (0,1), (0,2), and (0,3). In the last example one truck follows (0,1), another follows (0,4,6), and the last one follows (0,2,3,5,7).