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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int d[105][105];
int main()
{
	int n,p;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			d[i][j]=INF;
			if(i==j)d[i][j]=0;
		}
	}
	for(int i=0;i<n;i++)
	{
		int r,k;
		cin >> r >> k;
		r--;
		for(int j=0;j<k;j++)
		{
			int to;
			cin >> to;
			to--;
			d[r][to]=1;
		}
	}
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	cin >> p;
	for(int i=0;i<p;i++)
	{
		int from,to,TTL;
		cin >> from >> to >> TTL;
		from--;to--;
		if(d[from][to]<TTL)cout << d[from][to]+1 << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
const int maxv=1000;
int main()
{
	int root[101][101];
	for(int i=0;i<10;i++){
		for(int i2=0;i2<10;i2++){
			root[i][i2]=maxv;
		}
	}
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	int r,k,ch;
	cin>>r>>k;
		for(int i2=0;i2<k;i2++){
			cin>>ch;
			root[r][ch]=1;
		}
	}

	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int i2=01;i2<=n;i2++){
				root[i][i2]=min(root[i][i2],root[i][k]+root[k][i2]);
			}
		}
	}

	int m;
	int s,d,v;
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>s>>d>>v;
		if(v-root[s][d]>0){
			cout<<root[s][d]+1<<endl;
		}
		else{
			cout<<"NA"<<endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
const int maxv=100000;
int main()
{
	int root[101][101];
	for(int i=0;i<10;i++){
		for(int i2=0;i2<100;i2++){
			root[i][i2]=maxv;
		}
	}
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	int r,k,ch;
	cin>>r>>k;
		for(int i2=0;i2<k;i2++){
			cin>>ch;
			root[r][ch]=1;
		}
	}

	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int i2=01;i2<=n;i2++){
				root[i][i2]=min(root[i][i2],root[i][k]+root[k][i2]);
			}
		}
	}

	int m;
	int s,d,v;
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>s>>d>>v;
		if(root[s][d]<v){
			cout<<root[s][d]+1<<endl;
		}
		else{
			cout<<"NA"<<endl;
		}
	}
}

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

#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back 

int bfs(int s, int t, int c);

vector<vector<int> > g(101);

int main()
{
    int n;
    cin >> n;
    loop(i, n) {
        int r, k, t;
        cin >> r >> k;
        loop(j, k) {
            cin >> t;
            g[r].pb(t);
        }
    }
    int p;
    cin >> p;
    loop (i, p) {
        int s, d, v;
        cin >> s >> d >> v;
        int ans = bfs(s, d, v);
        if (ans != -1) {
            cout << v-ans << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

int bfs(int s, int t, int c)
{
    vector<bool> check(101, false);
    queue<int> fq, nq, sq;
    fq.push(s);
    while (1) {
        c--;
        while (!fq.empty()) {
            int pos = fq.front(); fq.pop();
            if (check[pos]) {
                continue;
            } else {
                check[pos] = true;
            }
            //cout << pos << endl;
            if (pos == t) {
                return c;
            } else {
                for (int i: g[pos]) {
                    nq.push(i);
                }
            }
        }
        if (c == 0 || nq.empty()) {
            return -1;
        }
        fq = nq;
        nq = sq;
    }
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
 



const int MAX_V = 100;
 
int d[MAX_V][MAX_V];
int V;
  
void warshall_floyd_init(){
    for(int i = 0; i < V; i++){
        for(int j = 0; j < V; j++){
            if(i == j) d[i][i] = 0;
            else d[i][j] = INF;
        }
    }
}
 
void warshall_floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}



 int main(){
 	cin>>V;
 	warshall_floyd_init();
 	int r, k, t;
 	for(int i = 0; i < V; i++){
 		cin>>r>>k;
 		r--;
 		for(int j = 0; j < k; j++){
 			cin>>t;
 			t--;
 			d[r][t] = 1;
 		}
 	}
 	warshall_floyd();

 	int p;
 	cin>>p;
 	for(int i = 0; i < p; i++){
 		cin>>r>>k>>t;
 		r--; k--;
 		if(d[r][k] < t){
 			cout<<d[r][k] + 1<<endl;
 		}
 		else cout<<"NA"<<endl;
 	}
 }

C++: #include <iostream>
#include <queue>
#include <map>
#include <climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> NODE;
#define pos first
#define depth second

bool info[100][100];

int bfs(int s,int d){
	queue<NODE> Q;
	bool done[100]={false};
	
	Q.push( make_pair(s,0) );
	while( !Q.empty() ){
		/* queueツづ個静ヲツ督ェツづ個ノツーツドツづーツ訪ツ姪「ツ催渉づ敖づ可つオツづowツ陛渉青板づ可禿シツづェツ、ツキツδーツつゥツづァツ偲ヲツづィツ渉慊つュ */
		NODE now = Q.front();
		Q.pop();
		done[now.pos] = true;

		if(now.pos == d){
			return now.depth;
		}

		for(int next=0;next<100;next++){
			if( !done[next] && info[now.pos][next] ){
				Q.push( make_pair(next,now.depth+1) );
			}
		}
	}
	return INT_MAX;
}

int main(){
	int n,r,k,t,p,s,d,v;
	
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r >> k;
		r--;
		for(int j=0;j<k;j++){
			cin >> t;
			t--;
			info[r][t] = true;
		}
	}	
	
	cin >> p;
	for(int i=0;i<p;i++){
		cin >> s >> d >> v;
		s--;d--;
		if(v > bfs(s,d) )cout << bfs(s,d)+1 << endl;
		else cout << "NA" << endl;
	}
}