/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam042 */ import java.util.Scanner; public class invasion { public static class G { public static int nodes; public static int roads; public static int bases; public static int distance; public static int[][] graph; public static int[] aliensLocation; public static boolean[] safe; } static Scanner scanner; public static void main(String[] args) { scanner = new Scanner(System.in); while(1==1) { String line = scanner.nextLine(); if (line.equals("0 0 0 0")) break; if (line.equals("")) continue; String[] parts = line.split(" "); G.nodes = Integer.parseInt(parts[0]); G.roads = Integer.parseInt(parts[1]); G.bases = Integer.parseInt(parts[2]); G.distance = Integer.parseInt(parts[3]); G.graph = new int[G.nodes][G.nodes]; for (int i = 0; i < G.nodes; i++) { for (int j = 0; j < G.nodes; j++) { if (i!=j) G.graph[i][j] = Integer.MAX_VALUE; } } for (int i = 0; i < G.roads; i++) { line = scanner.nextLine(); parts = line.split(" "); int from = Integer.parseInt(parts[0]) - 1; int to = Integer.parseInt(parts[1]) - 1; int length = Integer.parseInt(parts[2]); G.graph[from][to] = length; G.graph[to][from] = length; } G.aliensLocation = new int[G.bases]; for (int i = 0; i < G.bases; i++) { line = scanner.nextLine(); G.aliensLocation[i] = Integer.parseInt(line) - 1; } for (int k = 0; k < G.nodes; k++) for (int i = 0; i < G.nodes; i++) for (int j = 0; j < G.nodes; j++) { int ik = G.graph[i][k]; int kj = G.graph[k][j]; int ij = G.graph[i][j]; if (ik == Integer.MAX_VALUE || kj == Integer.MAX_VALUE) continue; if (ik + kj < ij) G.graph[i][j] = ik + kj; } /*for (int i = 0; i < G.nodes; i++) { for (int j = 0; j < G.nodes; j++) { System.out.print(G.graph[i][j]+" "); } System.out.println(); }*/ G.safe = new boolean[G.nodes]; for (int i = 0; i < G.nodes; i++) G.safe[i] = true; int goodOne = G.nodes; for (int i = 0; i < G.bases; i++) { int newBase = G.aliensLocation[i]; if (G.safe[newBase] == true) { G.safe[newBase] = false; goodOne--; } for (int j = 0; j < G.nodes; j++) { if (G.graph[newBase][j] < G.distance && G.graph[newBase][j] != Integer.MAX_VALUE) { if (G.safe[j] == true) { G.safe[j] = false; goodOne--; } } } System.out.println(goodOne); } if (G.bases == 0) System.out.println(G.nodes); System.out.println(); } } }