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 <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(ttl - d[dest] >= 0){
            cout << d[dest];
        }else{
            cout << "NA";
        }
        cout << endl;
    }
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    cin>>n;
    int d[200][200];
    rep(i,200){
        rep(j,200){
            if(i==j)d[i][j] = 0;
            else d[i][j] = 1<<20;
        }
    }
    rep(i,n){
        int src,k;
        cin>>src>>k;
        src--;
        rep(j,k){
            int dst;cin>>dst;
            dst--;
            d[src][dst] = 1;
        }
    }

    rep(k,n)rep(i,n)rep(j,n){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    }

    int p;cin>>p;
    rep(i,p){
        int s, t, ttl;
        cin >> s >> t >> ttl;
        --s; --t;
        if(d[s][t] >= ttl) puts("NA");
        else printf("%d\n", d[s][t] + 1);
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

vector<int>rinsetu[100]{};
unordered_map<int, int>taiou;
int main() {
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d; scanf("%d%d", &c, &d);
		taiou[c] = b;
		for (int e = 0; e < d; e++) {
			int f; scanf("%d", &f);
			rinsetu[b].push_back(f);
		}
	}
	int b; cin >> b;
	for (int c = 0; c < b; c++) {
		int g, h, i; scanf("%d%d%d", &g, &h, &i);
		int e[100]{};
		memset(e, -1, sizeof(e));
		queue<int>Q;
		e[taiou[g]] = 1;
		Q.push(g);
		while (Q.size()) {
			int o = Q.front(); Q.pop();
			o = taiou[o];
			if (e[o] > i)break;
			for (int p : rinsetu[o]) {
				if (e[taiou[p]] == -1) {
				 e[taiou[p]] = e[o] + 1; Q.push(p);
				}
			}
		}
		if (e[taiou[h]] == -1||e[taiou[h]]>i)puts("NA");
		else cout << e[taiou[h]] << endl;
	}
}

C++: /* ????????????????????????????????????????????? */
#include <stdio.h>

/* ?????°???????????? */
typedef	void			VD;
typedef	signed char		I1;
typedef unsigned char 	U1;
typedef	signed short	I2;
typedef unsigned short 	U2;
typedef	signed int		I4;
typedef unsigned int 	U4;

/* ?????°?????? */
#define MAX_ROUTER 100
#define MAX_TTL 10000

#define CONNECT 1
#define DISCONNECT 0
#define SENTINEL -1

#define TRUE 1
#define FALSE 0

#define INPUT_SUCCESS 0
#define INPUT_ERORR -1

/* ????????????????????£?¨? */
VD setInit(VD);
I1 inputConnectInfo(VD);
I1 inputTransmitPacket(VD);
I4 CalcSumRouter(I4 i4Sender,I4 i4Destination,I4 i4TTL);
/* ??°?????????????????° */
I1 u1Connect[MAX_ROUTER+1][MAX_ROUTER+1];
I4 i4RouterNum;

/* main??? */
I4 main(VD)
{
	I1 i1ErrorCheck;
	I4 i4CalcNum;
	I4 i4RoopCnt1;
	I4 i4RoopCnt2;
	
	setInit();
	i1ErrorCheck = inputConnectInfo();
	if(i1ErrorCheck == INPUT_SUCCESS){
		scanf("%d",&i4CalcNum);
		for( i4RoopCnt1=0; i4RoopCnt1<i4CalcNum; i4RoopCnt1++)
		{
			inputTransmitPacket();
		}
	}
	else{
		;
	}
	return 0;
}

/* ???????????¢??° */
VD setInit(VD)
{
	I4 i4RoopCnt1;
	I4 i4RoopCnt2;
	
	for( i4RoopCnt1=1; i4RoopCnt1<=MAX_ROUTER; i4RoopCnt1++)
	{
		for(i4RoopCnt2=1; i4RoopCnt2<=MAX_ROUTER; i4RoopCnt2++)
		{
			u1Connect[i4RoopCnt1][i4RoopCnt2] = DISCONNECT;
		}
	}
	return;
}

/* ??????????????\?¶??????±??\?????¢??° */
I1 inputConnectInfo(VD)
{
	I1 i1Return;
	I4 i4RoopCnt1;
	I4 i4RoopCnt2;
	I4 i4RouterCnt;
	I4 i4ConnectNum;
	I4 i4AccessPoint;
	
	i1Return = INPUT_SUCCESS;
	
	scanf("%d",&i4RouterNum);
	if(i4RouterNum <= (I4)MAX_ROUTER){
		for( i4RoopCnt1=1; i4RoopCnt1<=i4RouterNum; i4RoopCnt1++){
			scanf("%d%d",&i4RouterCnt,&i4ConnectNum);
			for( i4RoopCnt2=0; i4RoopCnt2<i4ConnectNum; i4RoopCnt2++){
				scanf("%d",&i4AccessPoint);
				u1Connect[i4RouterCnt][i4AccessPoint] = CONNECT;
			}
			u1Connect[i4RouterCnt][i4RouterNum+1] = SENTINEL;
		}
	}
	else{
		i1Return = INPUT_ERORR;
	}
	return i1Return;
}

/* ???????????±???????????±??\?????¢??° */
I1 inputTransmitPacket(VD)
{
	I1 i1Return;
	I4 i4StartRouter;
	I4 i4GoalRouter;
	I4 i4TTL;
	I4 i4Ans;
	
	i1Return = INPUT_SUCCESS;
	
	scanf("%d%d%d",&i4StartRouter,&i4GoalRouter,&i4TTL);
	if(i4TTL <= MAX_TTL){
		i4Ans = CalcSumRouter(i4StartRouter,i4GoalRouter,i4TTL);
		if(i4Ans > 0){
			printf("%d\n",i4Ans);
		}
		else{
			printf("NA\n");
		}
	}
	else{
		i1Return = INPUT_ERORR;
	}
	return i1Return;
}

/* ??????????????????????¨????????????°?¨??????¢??° */
I4 CalcSumRouter(I4 i4Sender,I4 i4Destination,I4 i4TTL)
{
	/* ?????°??£?¨? */
	I1 i1StarTable[MAX_ROUTER+1][MAX_ROUTER+1];	/* ????????¨ */
	I4 i4MinVal[MAX_ROUTER+1];
	I4 i4RoopCnt1;
	I4 i4RoopCnt2;
	I4 i4RoopCnt3;
	I4 i4RoopMax;
	
	/* ????????? */
	for( i4RoopCnt1=1; i4RoopCnt1<=MAX_ROUTER; i4RoopCnt1++){
		i4MinVal[i4RoopCnt1] = 0;
		for(i4RoopCnt2=1; i4RoopCnt2<=MAX_ROUTER; i4RoopCnt2++){
			i1StarTable[i4RoopCnt1][i4RoopCnt2] = FALSE;
		}
	}
	
	if(i4TTL<=MAX_ROUTER){
		i4RoopMax = i4TTL;
	}
	else{
		i4RoopMax == MAX_ROUTER;
	}
	
	i1StarTable[1][i4Sender] = TRUE;
	
	for(i4RoopCnt1=1; i4RoopCnt1<i4RoopMax; i4RoopCnt1++){
		for(i4RoopCnt2=1; i4RoopCnt2<=MAX_ROUTER; i4RoopCnt2++){
			if(i1StarTable[i4RoopCnt1][i4RoopCnt2] == TRUE){
				for(i4RoopCnt3=1; i4RoopCnt3<=MAX_ROUTER; i4RoopCnt3++){
					if(u1Connect[i4RoopCnt2][i4RoopCnt3] == CONNECT){
						if(i4RoopCnt3 == i4Destination){
							return i4RoopCnt1+1;
						}
						else{
							;
						}
						i1StarTable[i4RoopCnt1+1][i4RoopCnt3] = TRUE;
					}
					
				}
			}
			else{
				;
			}
		}
	}
	return 0;
}