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>
#include<cstdio>
#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



}



//L[(ÊÌzñÅà¢¢¯Ç)ÉÇñÇñüêÄ¢«TTLªO¢ÉÈéOÉÚInÉBÅ«é©Ç¤©ð²×é
//[^ÍÚInÉBµ½n_ÌTTL©çvZµÄ¾·
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; //I¹ð
    //cout << "next.second = " << next.second << endl; 
    
    for(i=1;i<=maxx;i++){//¢¯éêðL[Éüêé
      if(net[next.first][i] == 1)mem++;  

    
      
      if(net[next.first][i] == 1 && i == ed ){ //ÚInB
	/*	
	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;
  
  
  
}

C++: #include <iostream>
#include <limits.h>
#include <algorithm>
using namespace std;
int main(){
  int n;
  int r,k,t;
  int p;
  int s,d,b;
  int ans=0;
  int box[111][111];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      box[i][j]=INT_MAX;
    }
  }
  for(int i=0;i<n;i++){
    cin >> r >> k;
    for(int j=0;j<k;j++){
      cin >> t;
      box[r-1][t-1]=1;
    }
  }
  for(int z=0;z<n;z++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	box[i][j]=min(box[i][j],box[i][z]+box[z][j]);
      }
    }
  }
  cin >> p;
  for(int i=0;i<p;i++){
    cin >> s >> d >> b;
    ans=box[s-1][d-1]+1;
    if(ans<=b){
      cout << box[s-1][d-1]+1 << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

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

int main(){
    using namespace std;

    int n, M[101][101] = {};
    cin >> n;
    for(int i = 0; i < n; ++i){
        int num, src;
        cin >> src >> num;
        for(int j = 0; j < num; ++j){
            int dest;
            cin >> dest;
            M[src][dest] = 1;
        }
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; ++i){
        int src, dest, ttl, d[n + 1];
        fill(d, d + n + 1, -1);

        cin >> src >> dest >> ttl;
        d[src] = 1;
        queue<int> q;
        q.push(src);
        while(!q.empty()){
            int const u = q.front();
            q.pop();
            for(int v = 1; v < n + 1; ++v){
                if(M[u][v] == 1 && d[v] == -1){
                    d[v] = d[u] + 1;
                    q.push(v);
                }
            }
        }
        if(d[dest] == -1){
            cout << "NA";
        }else if(ttl - d[dest] >= 0){
            cout << d[dest];
        }else{
            cout << "NA";
        }
        cout << endl;
    }
}

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

#define N 101

int M[N][N];//&#65533;&#1488;&#1677;s&#65533;
int d[N];//&#65533;m&#65533;[&#65533;h&#65533;&#784;&#65533;
int pi[N];//&#65533;&#450;&#65533;&#65533;&#65533;&#65533;&#30152;&#65533;&#65533;&#65533;&#65533;

void initi();
int BFS(int start,int goal);


main(){
  initi();
  int n;
  cin >> n;
  for(int i = 0; i< n ; i++){
    int Bangou,setuzokusu;
    cin >> Bangou;
    cin >> setuzokusu;
    for(int j=0;j < setuzokusu ; j++){
      int to;
      cin >> to;
      M[Bangou][to]=1;
    }
  }//&#65533;f&#65533;[&#65533;^&#65533;&#787;&#65533;&#65533;&#834;&#65533;&#65533;&#65533;&#65533;&#1794;
  
  
  cin >> n;
  for(int i = 0; i < n;i++){
    int start,goal,TTL,result;
    cin >> start >> goal >> TTL;
    if ( (result =BFS(start,goal)+1) > TTL)cout << "NA" << endl;
    else cout << result << endl;
  }
  
  
  
  
  return 0;     
}


void initi(){
        for(int i=0;i<N;i++){
                for(int j=0;j<N;j++)M[i][j]=0;
        }
}

int BFS(int start,int goal){
        
  queue<int> Q;//&#65533;L&#65533;&#65533;&#65533;[&#65533;&#65533;&#65533;p&#65533;
  for(int i=0;i<N;i++){
    d[i] =1 << 21;
    pi[i]=0;
  }
  
  d[start]=0;
  Q.push(start);
  
  while(!Q.empty()){//&#65533;L&#65533;&#65533;&#65533;[&#65533;&#65533;&#65533;&#65533;&#65533;&#578;&#514;&#65533;&#65533;&#1794;&#322;&#65533;&#65533;
    int u=Q.front();
    Q.pop();
    //  cout << "Now u is" << u << endl;
    for(int v = 0 ; v <N ; v++){
      if (M[u][v] && d[v] == 1 << 21){//u&#65533;&#65533;&#65533;&#65533;v&#65533;&#589;s&#65533;&#65533;&#65533;&#269;X&#65533;&#65533;v&#65533;&#771;X&#65533;^&#65533;[&#65533;g&#65533;n&#65533;_&#65533;&#65533;&#65533;&#65533;&#65533;&#779;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#337;&#65533;&#65533;&#782;&#65533;
        d[v]=d[u]+1;
        pi[v]=u;//&#65533;&#450;&#65533;&#65533;&#65533;&#65533;&#30152;&#65533;&#65533;&#65533;&#65533;
        Q.push(v);
        //cout <<"from "  <<u << "to" <<v << endl;
      }
    }
  }

  //for(int i=1;i<8;i++)cout << d[i]<< " ";
  //cout << endl;
  
  
  return d[goal];
        
}