Language: C

int *queue;
int head;
int tail;

void enqueue(int);
int dequeue(void);
void bfs(void);


int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  queue = malloc(n * sizeof(int));
  color = malloc((n+1) * sizeof(int));
  dist = malloc((n+1) * sizeof(int));
 
  
  matrix = malloc((n+1) * sizeof(int *));
  for(i=0;i<n+1;i++) matrix[i] = malloc((n+1) * sizeof(int));


  for(i=1;i<n+1;i++) dist[i] = -1;
  
  for(i=1;i<n+1;i++)
    for(j=1;j<n+1;j++)
      matrix[i][j] = 0;
  
  
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      matrix[u][v] = 1;
    }
  }


  bfs();
 

  for(i=1;i<n+1;i++) printf("%d %d\n",i,dist[i]);

  free(matrix);

  return 0;
}

void bfs(){
  int u,i;

  head = tail = 0;
  color[1] = WHITE;
  dist[1] = 0;
  enqueue(1);
  
  while(head != tail){
    u = dequeue();
    for(i=1;i<n+1;i++){
      if(matrix[u][i] == 1 && color[i] == WHITE){
	color[i] = GRAY;
	dist[i] = dist[u] + 1;
	enqueue(i);
      }
    }
    color[i] = BRACK;
  }
}

void enqueue(int q){
  
  queue[tail] = q;
  if(tail++ == n) tail = 0;
  
}

int dequeue(){
  int v;
  
  v = queue[head];
  if(head++ == n) head=0;
  return v;

}

Compiler output:
main.c: In function 'main':
main.c:13:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   13 |   scanf("%d",&n);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | int *queue;
main.c:13:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   13 |   scanf("%d",&n);
      |   ^~~~~
main.c:13:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:13:15: error: 'n' undeclared (first use in this function)
   13 |   scanf("%d",&n);
      |               ^
main.c:13:15: note: each undeclared identifier is reported only once for each function it appears in
main.c:15:11: error: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
   15 |   queue = malloc(n * sizeof(int));
      |           ^~~~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
  +++ |+#include <stdlib.h>
    1 | int *queue;
main.c:15:11: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
   15 |   queue = malloc(n * sizeof(int));
      |           ^~~~~~
main.c:15:11: note: include '<stdlib.h>' or provide a declaration of 'malloc'
main.c:16:3: error: 'color' undeclared (first use in this function)
   16 |   color = malloc((n+1) * sizeof(int));
      |   ^~~~~
main.c:17:3: error: 'dist' undeclared (first use in this function)
   17 |   dist = malloc((n+1) * sizeof(int));
      |   ^~~~
main.c:20:3: error: 'matrix' undeclared (first use in this function)
   20 |   matrix = malloc((n+1) * sizeof(int *));
      |   ^~~~~~
main.c:44:22: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   44 |   for(i=1;i<n+1;i++) printf("%d %d\n",i,dist[i]);
      |                      ^~~~~~
main.c:44:22: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:44:22: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:44:22: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:46:3: error: implicit declaration of function 'free' [-Wimplicit-function-declaration]
   46 |   free(matrix);
      |   ^~~~
main.c:46:3: note: include '<stdlib.h>' or provide a declaration of 'free'
main.c:46:3: warning: incompatible implicit declaration of built-in function 'free' [-Wbuiltin-declaration-mismatch]
main.c:46:3: note: include '<stdlib.h>' or provide a declaration of 'free'
main.c: In function 'bfs':
main.c:55:3: error: 'color' undeclared (first use in this function)
   55 |   color[1] = WHITE;
      |   ^~~~~
main.c:55:14: error: 'WHITE' undeclared (first use in this function)
   55 |   color[1] = WHITE;
      |              ^~~~~
main.c:56:3: error: 'dist' undeclared (first use in this function)
   56 |   dist[1] = 0;
      |   ^~~~
main.c:61:15: error: 'n' undeclared (first use in this function)
   61 |     for(i=1;i<n+1;i++){
      |               ^
main.c:62:10: error: 'matrix' undeclared (first use in this function)
   62 |       if(matrix[u][i] == 1 && color[i] == WHITE){
      |          ^~~~~~
main.c:63:20: error: 'GRAY' undeclared (first use in this function)
   63 |         color[i] = GRAY;
      |                    ^~~~
main.c:68:16: error: 'BRACK' undeclared (first use in this function)
   68 |     color[i] = BRACK;
      |                ^~~~~
main.c: In function 'enqueue':
main.c:75:16: error: 'n' undeclared (first use in this function)
   75 |   if(tail++ == n) tail = 0;
      |                ^
main.c: In function 'dequeue':
main.c:83:16: error: 'n' undeclared (first use in this function)
   83 |   if(head++ == n) head=0;
      |                ^