Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int lookup(int x, int *n, int *a)
- {
- int i;
- for (i=0;i<*n; i++) if(a[i] == x) return i;
- a[*n] = x;
- ++*n;
- return *n-1;
- }
- void touch(int ttl, int node, int con[][30], int n, int hit[])
- {
- int i;
- hit[node] = 1;
- if (!ttl) return;
- for (i=0; i<n; i++) if(con[node][i]) touch(ttl-1,i,con,n,hit);
- }
- int main()
- {
- int c=1,i,j,k,m,con[30][30],nodes[30],n,n_con,hit[30];
- while(scanf("%d",&n_con),n_con)
- {
- for (i=0;i<30;i++) for(j=0;j<30;j++)con[i][j]=0;
- n=0;
- for(i=0;i<n_con;i++)
- {
- scanf("%d %d",&j,&k);
- j=lookup(j,&n,nodes);
- k=lookup(k,&n,nodes);
- con[j][k]=con[k][j]=1;
- }
- while(scanf("%d %d",&j,&k),j||k)
- {
- for(i=0;i<n;i++) hit[i]=0;
- touch(k,lookup(j,&n,nodes),con,n,hit);
- for(m=0,i=0;i<n;i++) if (!hit[i]) m++;
- printf("Case %d: %d nodes not reachable from node %d with TTL = %d.\n", c++, m, j, k);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement