Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const INF = 1<<31

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	arr := make([][]int, n)
	for i := range arr {
		arr[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			arr[i][j] = INF
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		buf := strings.Split(scanner.Text(), " ")
		input := make([]int, len(buf))
		for j := range input {
			input[j], _ = strconv.Atoi(buf[j])
		}
		x, k := input[0]-1, input[1]
		for j := 0; j < k; j++ {
			y := input[j+2]-1
			arr[x][y] = 1
		}
	}
	for k := 0; k < n; k++ {
		arr[k][k] = 0
		for i := 0; i < n; i++ {
			if arr[i][k] >= INF {
				continue
			}
			for j := 0; j < n; j++ {
				if arr[k][j] >= INF {
					continue
				}
				arr[i][j] = min(arr[i][j], arr[i][k]+arr[k][j])
			}
		}
	}
	scanner.Scan()
	p, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < p; i++ {
		scanner.Scan()
		buf := strings.Split(scanner.Text(), " ")
		input := make([]int, len(buf))
		for j := range input {
			input[j], _ = strconv.Atoi(buf[j])
		}
		s, d, v := input[0]-1, input[1]-1, input[2]
		if arr[s][d] < v {
			fmt.Println(arr[s][d]+1)
		} else {
			fmt.Println("NA")
		}
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

C++: #include<iostream>

int main(void)
{
  int n,p,r,k,t[101],a,count[101],flag;
  int queue[10000],head=0,tail=0;
  int router[101][101],visited[101],i,j,b,fg;
  
  struct mail{
    int s;
    int d;
    int v[101];
  }packet[101];
  
  for(i=0;i<101;i++)
    {
      for(j=0;j<101;j++)
	{
	  router[i][j]=0;
	}
    }
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&r,&k);
      
      for(j=1;j<=k;j++)
	{
	  scanf("%d",&t[j]);
	  router[r][t[j]]=1;
	}
    }
  
  for(i=1;i<=n;i++)
    {
      router[i][i]=0;
    }
  
  scanf("%d",&p);
  
  for(i=1;i<=p;i++)
    {
      scanf("%d%d%d",&packet[i].s,&packet[i].d,&packet[i].v[1]);
    }
  
  for(i=1;i<=p;i++)
    {
      for(j=1;j<=p;j++)
	{
	  packet[i].v[j]=packet[i].v[1];
	}
    }
  
  for(i=1;i<=p;i++)
    {
      //printf("A\n");
      count[packet[i].s]=1;
      queue[tail++]=packet[i].s;
      
      for(b=0;b<=n;b++)
	visited[b]=0;
      
      visited[packet[i].s]=1;
      fg=0;
      //printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
      while(head!=tail)
	{
	  
	  a=queue[head++];
	  
	  for(j=1;j<=n;j++)
	    {
	      //printf("%dB\n",packet[i].v[j]);
	      //printf("%d\n",packet[i].v[j]);
	      
	      if(router[a][j]==1 && visited[j]==0)
		{
		  queue[tail++]=j;
		  visited[j]=1;
		  count[j]=count[a]+1;
		  packet[i].v[j]=packet[i].v[a]-1;
		  //printf("%d==%d\n",j,packet[i].d);
		  if(j==packet[i].d && packet[i].v[j]>0)printf("%d\n",count[packet[i].d]);
		  else if(fg==0 && packet[i].v[j]==-1 && a!=packet[i].d)
		    {
		      printf("NA\n");
		      fg=1;
		    }
		  
		} 
	      
	    }
	  //printf("\n");
	}
      
    }
  return 0;
}

C++: #include <iostream>
#include <queue>
using namespace std;

int main(){
  int a,b,c,d,e,f,g,now,v[101],m[101][101]={};
  queue<int> q;
  cin >> a;
  for(int i=1;i<=a;i++){
    cin >>b>>c;
    for(int j=0;j<c;j++){
      cin >> d;
      m[i][d]=1;
    }
  }
  cin >> d;
  for(int i=0;i<d;i++){
    cin >> e >> f >> g;
    q.push(e);
    for(int j=1;j<=a;j++)v[j]=1200;
    v[e]=1;
    while(1){
      now=q.front();q.pop();
      if(now==f){
	if(v[f]>g){
	  cout << "NA" << endl;
	  break;
	}else {
	  cout << v[now] << endl;
	  break;
	}
      }
      for(int j=1;j<=a;j++){
	if(m[now][j]==1&&v[j]==1200){
	  v[j]=v[now]+1;
	  q.push(j);
	}
      }
      if(q.empty()){
	cout<< "NA" << endl;
	break;
      }
    }
    while(!q.empty())q.pop();
  }
  return 0;
}

C++: #include<iostream>
#include<queue>

using namespace std;

int main(){

  int n;
  cin >> n;
  
  int data[n+1][n+1];
  
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n; j++){
      data[i][j] = 0;
    }
  }
  
  int from, to, conesum;
  
  for(int i = 0; i < n; i++){
    cin >> from >> conesum;
    for(int j = 0; j < conesum; j++){
      cin >> to;
      data[from][to] = 1;
    }
  }
  
  
  int sumpake;
  cin >> sumpake;
  
    queue<int> Q;

    int ttl, myposi, min, sumin, sumina, finish = 0;

    for(int i = 0; i < sumpake; i++){
      min = 0;
      cin >> from >> to >> ttl;
      if(ttl == 0) {
	cout << "NA" << endl;
	continue;
      }
      myposi = from;
      for(int j = 0; j < ttl; j++){
	if(j != 0){
	  for(int l = 0; l < sumina; l++){
	    if(Q.front() == to){
	      min = j;
	      finish = 1;
	      break;
	    }
	    myposi = Q.front();
	    Q.pop();
	    for(int k = 1; k <= n; k++){
	      if(data[myposi][k] == 1) {
		Q.push(k);
		sumin++;
	      }
	    }
	    
	  }
	  if(finish == 1) break;
	}else{
	  sumin = 0;
	  for(int k = 1; k <= n; k++){
	    if(data[myposi][k] == 1) {
	      Q.push(k);
	      sumin++;
	    }
	  }
	  
	}
	  sumina = sumin;
	  sumin = 0;
      }
      
      if(min == 0) cout << "NA";
      else cout << min+1;
      cout << endl;
      finish = 0;
      while(!Q.empty()) Q.pop();
    }

  return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
#define SUB 103

int net[SUB][SUB],n,maxx=0;

typedef pair<int,int> BVB;


int ans(int,int,int);



int main(){

 

  int i,j,p,num,n1,th;

  cin >> n;



  for(i=0;i<n;i++){ //net's info
    
    cin >> num >> n1;
    if(num >= maxx)maxx = num;


    for(int k=0;k<maxx;k++)net[num][k]=0;    //siyoukanou

    for(j=0;j<n1;j++){
      cin >> th;
      net[num][th]=1;
    }

  }//net's info
  // cout << "maxx =" << maxx << endl;
  for(int m=0;m<maxx;m++){
    for(int n=0;n<maxx;n++){
      if(net[m][n]!=1)net[m][n]=0;
    }
  }

  

  int pkn;

  cin >> pkn;

  int st,ed,c,answer;

  



  for(i=0;i<pkn;i++){//pack's info
    cin >> st >> ed >> c;


    answer = ans(st,ed,c);

    if(answer != -2)cout << answer << endl;
    else cout << "NA" << endl;

  }//pack's info



}

int ans(int st,int ed,int c){
  queue<BVB> Nari;
  int i,j,k,l,cal=0,mem=0;
  BVB next,fr;

  fr.first=st;
  fr.second=c;
  Nari.push(fr);
  /*
  cout << "FIRST next.second = " << c << endl;  
  cout << "FIRST cal = " << cal << endl;
  */  

  if(st == ed && c != 0)return 1;


  while(1){
    next=Nari.front();
    Nari.pop();
    next.second=next.second-1;

    if(fr.second == (next.second+1) && next.second == 0 && next.first != ed)return -2;

    if(next.second < 0)break; 
    //cout << "next.second = " << next.second << endl; 
    
    for(i=1;i<=maxx;i++){
      if(net[next.first][i] == 1)mem++;  

    
      
      if(net[next.first][i] == 1 && i == ed ){ 
	/*	
	cout << "GOOOOOOOOOL!!! i = " << i <<endl;
	cout << "             cal = " << cal << endl;
	cout << "     next.second = " << next.second << endl; 
	*/

	return (fr.second - next.second)+1;
	
      }
      
      if(net[next.first][i] == 1)Nari.push(BVB(i,next.second));
      
      if(mem == n)break;
    }
      
    
  }

  return -2;
  
  
  
}