#include #include typedef struct SRoad{ struct SRoad * next; int where; int len; } Road; void insert( Road ** city, Road ** last, 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( Road ** city, int * dist, int where, int K ){ Road* r = city[where]; int lost = 0; //printf("Lookup from %d.\n",where+1); while(r!=NULL){ //printf("Road from %d(dist %d) to %d(dist %d) of length %d ",where+1, dist[where], r->where+1, dist[r->where], r->len); if( dist[r->where] > dist[where] + r->len ){ if(dist[r->where]==K) lost++; //printf("forcing new dist.\n"); dist[r->where] = dist[where] + r->len; lost += recBuild(city,dist,r->where,K); } //printf("ignored.\n"); r = r->next; } return lost; } int main(){ while(1){ int N,M,K,A; scanf( "%d %d %d %d", &N, &M, &K, &A ); if(!N && !N && !K && !A) return 0; Road ** city = (Road**) malloc( N*sizeof(Road*) ); Road ** last = (Road**) malloc( N*sizeof(Road*) ); int * dist = (int*) malloc( sizeof(int)*N ); int i; for(i=0;inext; free(t); } } free(city); free(last); free(dist); } return 0; }