#include #include typedef struct SRoad{ struct SRoad * next; int where; int len; } Road; Road ** city; Road ** last; void insert( int a, int b, int d ){ if( last[a] == NULL ){ city[a] = last[a] = (Road*) malloc( sizeof(Road) ); } else{ last[a] = last[a]->next = (Road*) malloc( sizeof(Road) ); } if( last[b]==NULL ){ city[b] = last [b] = (Road*) malloc( sizeof(Road) ); } else{ last[b] = last[b]->next= (Road*) malloc( sizeof(Road) ); } last[a]->where = b; last[b]->where = a; last[a]->len = last[b]->len = d; last[a]->next = NULL; last[b]->next = NULL; } int recBuild( int * dist, int where, int K ){ Road* r = city[where]; int lost = 0; while(r!=NULL){ if( dist[r->where] > dist[where] + r->len ){ if(dist[r->where]==K) lost++; dist[r->where] = dist[where] + r->len; lost += recBuild(dist,r->where,K); } r = r->next; } return lost; } int main(){ while(1){ int N=0,M=0,K=0,A=0; scanf( "%d %d %d %d", &N, &M, &K, &A ); if(!N && !N && !K && !A) return 0; city = (Road**) malloc( N*4 ); last = (Road**) malloc( N*4 ); int * dist = (int*) malloc( sizeof(int)*N ); int i; for(i=0;inext; free(t); } } free(city); free(last); free(dist); } return 0; }