#include #include #include #define MAXN 30000 #define MAXM 500000 #define MAXK 200 typedef struct EDGE { int From; int To; int Length; } EDGE; typedef struct FOL { int To; int Length; } FOL; EDGE Edge[MAXM]; int Degree[MAXN]; int CurIndex[MAXN]; FOL Fol[MAXM]; int iFol[MAXN]; int Base[MAXN]; int List[MAXK][MAXN]; int nList[MAXK]; int Dist[MAXN]; int main() { while(1) { int n, m, a, k; scanf("%d%d%d%d", &n, &m, &a, &k); k--; if(!(n)) { break; } memset(Degree, 0, sizeof(Degree)); for(int i = 0; i < m; i++) { scanf("%d%d%d", &(Edge[i].From), &(Edge[i].To), &(Edge[i].Length)); Edge[i].From--; Edge[i].To--; Degree[Edge[i].From]++; Degree[Edge[i].To]++; } iFol[0] = 0; for(int i = 0; i < n; i++) { iFol[i + 1] = iFol[i] + Degree[i]; } memset(CurIndex, 0, sizeof(CurIndex)); for(int i = 0; i < m; i++) { int e = Edge[i].From; Fol[iFol[e] + CurIndex[e]].To = Edge[i].To; Fol[iFol[e] + CurIndex[e]].Length = Edge[i].Length; CurIndex[e]++; e = Edge[i].To; Fol[iFol[e] + CurIndex[e]].To = Edge[i].From; Fol[iFol[e] + CurIndex[e]].Length = Edge[i].Length; CurIndex[e]++; } for(int i = 0; i < a; i++) { scanf("%d", Base + i); Base[i]--; } /*printf("Bases\n"); for(int i = 0; i < a; i++) { printf("%d ", Base[i]); } printf("\n"); for(int i = 0; i < n; i++) { printf("Followers of %d: ", i + 1); for(int j = iFol[i]; j < iFol[i + 1]; j++) { printf("%d ", Fol[j].To + 1); } printf("\n"); }*/ for(int i = 0; i < n; i++) { Dist[i] = 1 << 30; } int nSafe = n; for(int i = 0; i < a; i++) { if(Dist[Base[i]] == 1 << 30) { nSafe--; } List[0][nList[0]++] = Base[i]; Dist[Base[i]] = 0; for(int cdist = 0; cdist <= k;) { if(!(nList[cdist])) { cdist++; continue; } int cur = List[cdist][--nList[cdist]]; for(int j = iFol[cur]; j < iFol[cur + 1]; j++) { //printf("!\n"); int t = Fol[j].To; int l = Fol[j].Length; //printf("%d -> %d examined\n", cur + 1, t + 1); if(Dist[cur] + l > k) { continue; } if(Dist[t] > Dist[cur] + l) { if(Dist[t] == 1 << 30) { nSafe--; } Dist[t] = Dist[cur] + l; List[Dist[t]][nList[Dist[t]]++] = t; //printf("Vertex %d reached by %d\n", t + 1, Dist[t]); //printf("cdist; nList[1]: %d, %d\n", cdist, nList[1]); } } } printf("%d\n", nSafe); } printf("\n"); } return 0; }