Invasion
Time limit1sMemory limit128 MB
For each prefix of alien bases, count towns whose shortest-path distance to every base built so far is at least K.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Heap, Implementation
- Solved
- No attempts yet
Problem
An alien invasion has begun, and terrifying man-eating aliens are building bases all across the country. You are only safe in places that are sufficiently far from every alien base that currently exists. Write a program that quickly determines how many towns remain safe, so you know where to flee.
Input
The input consists of several instances, each spanning several lines. The first line of an instance contains four integers , , , and separated by spaces: the number of towns in the country, the number of roads between them, the number of bases the aliens are going to build, and the minimum safe distance from an alien base, respectively. The towns are numbered .
Each of the next lines describes one road and contains three integers , () and (), where is the length of the road between towns and . There is at most one direct road between any pair of towns, and every road can be used in both directions.
Each of the following lines describes the position of one base; the -th of them contains the number () of the town where the aliens build their -th base.
Each instance is followed by one blank line. The blank line after the last instance is followed by a line containing four zeros, which is not part of any instance.
Output
For each instance output lines. On the -th line print the number of towns that are safe once the aliens have built their -th base. A town is safe when the shortest road distance from it to each of the bases is at least ; a town that cannot be reached from a base is considered safe with respect to that base.
Separate the output blocks of two consecutive instances with a single blank line. Do not print a blank line after the final instance; the output ends with the newline that terminates its last line.