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>
using namespace std;

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

typedef pair<int,int> BVB;


int ans(int,int,int);

int main(){

  int num,n1,th;

  cin >> n;



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

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

  }//net's info
  
  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;



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


    if(ans(st,ed,c) != -2)cout << ans(st,ed,c) << endl;
    else cout << "NA" << endl;

  }//pack's info

}


int ans(int st,int ed,int c){
  queue<BVB> Nari;
  int yes=10001;
  BVB next,fr;

  fr.first=st;
  fr.second=c;
  Nari.push(fr);
  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; 
    
    for(int i=1;i<=maxx;i++){
      
      if(net[next.first][i] == 1 && i == ed ){ //ツ姪堋的ツ地ツ督楪達

	if(yes >  (c-next.second+1))yes = (c - next.second)+1;
	
	
      }
            
      if(net[next.first][i] == 1){
	Nari.push(BVB(i,next.second));

      }
      
    }
       
  }
  if(yes != 10001){return yes;}
  else return -2; 
}

C++: #include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int INF = 1000;

int main()
{
    int n, p;
    cin >> n;
    int w[n+1][n+1];
    for(int i = 1; i <= n; i++) 
        for(int j = 1; j <= n; j++) 
            w[i][j] = (i==j) ? 0 : INF;

    int r,k,t;
    for(int i = 1; i <= n; i++) {
        cin >> r >> k;
        for(int j = 0; j < k; j++) {
            cin >> t;
            w[r][t] = 1;
        }
    }

    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
            }
        }
    }
    
    cin >> p;
    int s,d,v;
    for(int i = 0; i < p; i++) {
        cin >> s >> d >> v;
        if(w[s][d] + 1 <= v) {
            cout << w[s][d] + 1 << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    
}

C++: //Name: Nature of Prime Numbers
//Level: 1
//Category: やるだけ
//Note: 問題文が読みにくい

/**
 * 問題文がかなり分かりにくいが、要するに
 * ・a_i = i^2 mod n (1 ≦ i < n)
 * ・S = unique set of a_i
 * ・d_j = (a - b) mod n (a, b ∈ S, a≠b)
 * ・e_j = max(0, min(d_j, n-d_j))
 * としたとき、e_jのヒストグラムを作れば良い。
 * 問題文の残りの部分は、nが素数かつn≡3 (mod 4) のときに、e_jのヒストグラムが
 * 平らになることを主張している。
 */
#include <iostream>
#include <vector>
#include <set>

using namespace std;

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    set<int> s;
    for(int i = 0; i < N-1; ++i) {
        s.insert((i+1)*(i+1) % N);
    }
    vector<int> hist((N-1)/2, 0);
    for(auto it1 = begin(s); it1 != end(s); ++it1) {
        for(auto it2 = begin(s); it2 != it1; ++it2) {
            int e = (*it1 - *it2 + N) % N;
            if(e > (N-1)/2) e = N - e;
            hist[e-1]++;
        }
    }
    for(int i : hist) {
        cout << i*2 << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	bool y[105][105] = {};


	int n; cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a,b; cin >> a>>b;
		for (int j = 0; j < b; j++) {
			int z;
			cin >> z;
			y[a][z] = 1;
		}
	}
	
	int p; cin >> p;
	for (int i = 0; i < p; i++) {
		int s, d, t;
		cin >> s >> d >> t;
		queue<int>Q;
		Q.push(s);
		int h = 1;
		int R[105] = {};
		for (int j = 0; j <= 102; j++)
			R[j] = 999999;
		R[s] = 1;
		while (Q.size()) {
			int v = Q.front();
			h = R[v];
			h++;
		
			
			bool F[105] = {};
			for (int j = 1; j <= n; j++) {
				if (y[v][j] && R[j] > h) {
					R[j] = h;
					Q.push(j);
				}



			}
			Q.pop();	
		}
/*		for (int j = 0; j < n; j++)
			cout << R[j] << " ";*/
		if (R[d] <= t)cout << R[d] << endl;
		else cout << "NA" << endl;
	}
	
	return 0;

}

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)
{
    queue<int> fq, nq, sq;
    fq.push(s);
    while (1) {
        c--;
        while (!fq.empty()) {
            int pos = fq.front(); fq.pop();
            //cout << pos << endl;
            if (pos == t) {
                return c;
            } else {
                for (int i: g[pos]) {
                    nq.push(i);
                }
            }
        }
        if (c == 0) {
            return -1;
        }
        fq = nq;
        nq = sq;
    }
}