Invasion

Time limit1sMemory limit128 MB

Summary
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 NN, MM, AA, and KK 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 1,…,N1, \dots, N.

  • 1≤N≤100001 \le N \le 10000
  • 0≤M≤1000000 \le M \le 100000
  • 0≤A≤N0 \le A \le N
  • 1≤K≤1001 \le K \le 100

Each of the next MM lines describes one road and contains three integers T1T_1, T2T_2 (1≤T1<T2≤N1 \le T_1 < T_2 \le N) and DD (1≤D≤1001 \le D \le 100), where DD is the length of the road between towns T1T_1 and T2T_2. 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 AA lines describes the position of one base; the ii-th of them contains the number BiB_i (1≤Bi≤N1 \le B_i \le N) of the town where the aliens build their ii-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 AA lines. On the ii-th line print the number of towns that are safe once the aliens have built their ii-th base. A town is safe when the shortest road distance from it to each of the bases B1,B2,…,BiB_1, B_2, \dots, B_i is at least KK; 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.

Examples1

  1. Example 1

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