#P10617. Centralized Traffic Management
Centralized Traffic Management
Centralized Traffic Management
You are tasked with designing an advanced centralized traffic management system for smart cars. In a city, intersections are connected by bidirectional roads with various travel times. All commuters start their journeys at the same time from different intersections and must reach downtown at intersection 1 along an optimal route (i.e. a route whose total travel time is minimum for that starting point). However, since the commuters are selfish, you cannot assign any route that is slower than their individual optimal travel time.
In addition, if two commuters start traveling along the same road in the same direction at the same time, a congestion occurs – this must be avoided. It is acceptable, however, for multiple commuters to be at the same intersection at the same time or to travel the same road if they start at different times.
More formally, let the city have n intersections and m bidirectional roads. Each road between intersections u and v has a travel time w. For each intersection i, let d(i) be the minimum travel time required to go from i to downtown (intersection 1). A commuter starting at intersection s may only use a road from u to v if
\[
d(u)=w+ d(v) \quad (\text{optimality condition})
\]
and if the commuter departs u at time t, then his arrival time at v is t+w. Note that a commuter starting at s will depart immediately at time 0 from s (so his departure time on the first road is 0) and, along an optimal path, his arrival time at any intersection u will be \(d(s)-d(u)\). Two commuters using the same road in the same direction simultaneously (i.e. with the same departure time) will cause congestion.
Your goal is to determine the maximum number of commuters that can reach downtown without congestion. For commuters who are already at downtown (intersection 1), no scheduling is needed. For the others, you may assign them any optimal route, subject to the restriction that if two commuters have the same starting d(s) value they must not start the same road at the same time. In other words, for each optimal road used (from u to v) and for each possible departure time, at most one commuter can take that road at that time.
Example: In the figure below, one car is already downtown. Four cars start at intersection 4. There are two distinct optimal routes from 4: one going through intersection 3 and another through intersection 2. Therefore, at most two of the cars at intersection 4 can be routed without congestion, and the maximum number of cars that can reach downtown is 3.
inputFormat
The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 2×105) representing the number of intersections and roads, respectively.
Then follow m lines, each containing three integers u, v, and w (1 ≤ u, v ≤ n, u ≠ v, 1 ≤ w ≤ 109), describing a bidirectional road between intersections u and v with travel time w.
The next line contains an integer k (1 ≤ k ≤ 105), which is the number of commuters.
The following k lines each contain a single integer s (1 ≤ s ≤ n) representing the starting intersection for a commuter.
Note: Intersection 1 is always downtown. All commuters start their journey simultaneously at time 0.
outputFormat
Output a single integer, the maximum number of commuters that can reach downtown (intersection 1) without congestion, while each commuter follows an optimal route.
sample
4 4
1 2 1
1 3 1
2 4 1
3 4 1
5
1
4
4
4
4
3