Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dd := make([][]int, 1000)
	for i := range dd {
		dd[i] = make([]int, 1000)
	}
	num := make([]int,1000)
	inv := make([]int, 1001)
	x := make([]int, 1000)
	y := make([]int, 1000)
	vv := make([]int, 1000)
	nowt := make([]float64, 1000)
	rev := make([]int, 1000)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf1 := strings.Split(scanner.Text(), " ")
			num[i], _ = strconv.Atoi(buf1[0])
			x[i], _ = strconv.Atoi(buf1[1])
			y[i], _ = strconv.Atoi(buf1[2])
			inv[num[i]] = i
		}
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				dd[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])
			}
		}
		scanner.Scan()
		m, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf2 := strings.Split(scanner.Text(), " ")
			c, _ := strconv.Atoi(buf2[0])
			d, _ := strconv.Atoi(buf2[1])
			c = inv[c]
			d = inv[d]
			for j := 0; j < n; j++ {
				vv[j] = 0
				nowt[j]=999999999
				rev[j]=-1
			}
			nowt[c]=0
			for j := 0; j < n; j++ {
				M := 99999999
				at := 0
				for k := 0; k < n; k++ {
					if vv[k] == 0 && float64(M) > nowt[k] {
						M=int(nowt[k])
						at = k
					}
				}
				if M > 90000000 {
					break
				}
				vv[at]=1
				for k := 0; k < n; k++ {
					if vv[k] == 0 && dd[at][k]<=2500&&nowt[k]>nowt[at]+math.Sqrt(float64(dd[at][k])) {
						nowt[k]=nowt[at]+math.Sqrt(float64(dd[at][k]))
						rev[k] = at
					}
				}
			}
			if vv[d] == 0 {
				fmt.Println("NA")
			} else {
				stack := make([]int, 0)
				V := d
				for V != c {
					stack = append(stack, V)
					V = rev[V]
				}
				fmt.Print(num[c])
				for len(stack) > 0 {
					fmt.Printf(" %d", num[stack[len(stack)-1]])
					stack = stack[:len(stack)-1]
				}
				fmt.Println()
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin >> n , n){
		double g[n][n];
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				g[i][j] = 100000000;
		int b[n] , x[n] , y[n];
		for(int i = 0; i < n; i++)
			cin >> b[i] >> x[i] >> y[i];
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++){
				int xx = x[i] - x[j],
					   yy = y[i] - y[j];
				if(sqrt(xx * xx + yy * yy) <= 50 && i != j)
					g[i][j] = g[j][i] = sqrt(xx * xx + yy * yy);
			}
		int m;
		cin >> m;
		int s , go;
		for(int i = 0; i < m; i++){
			cin >> s >> go;
			s--; go--;
			vector <int> used(n,false);
			vector <int> gone(n,false);
			vector <double> dist(n,100000000);
			dist[s] = 0;
			gone[s] = 0;
			while(1){
				int va = -1;
				for(int j = 0; j < n; j++)
					if(used[j] == false && (va == -1 || dist[va] > dist[j]))
						va = j;
				if(va == -1)
					break;
				used[va] = true;
				for(int j = 0; j < n; j++){
					if(dist[j] >= dist[va] + g[va][j])
						gone[j] = va;
					dist[j] = min(dist[j] , dist[va] + g[va][j]);
				}
			}
			if(s == go)
				cout << s + 1 << " " << go + 1 << endl;
			else if(dist[go] == 100000000)
				cout << "NA" << endl;
			else{
				int kari = go;
				stack <int> out;
				while(1){
					out.push(gone[kari] + 1);
					kari = gone[kari];
					if(kari == s)
						break;
				}
				while(!out.empty()){
					cout << out.top() << " ";
					out.pop();
				}
				cout << go + 1 << endl;
			}
		}
	}
}

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

const int MAX_V = 10001;
const int INF = 1e+8;
typedef pair<int,int> P;

struct edge{
	int to, cost;
	edge(int v, int cost_){
		to = v;
		cost = cost_;
	}
};

// 頂点数
int V;
// G[u][i] = ノード u に接続している i 番目の edge が返ってくる
vector<edge> G[MAX_V];
// 始点 s からの最短距離 (存在しない場合は INF )
int d[MAX_V];
// prev[v] := ノード v の直前に訪れた頂点 (存在しないときは -1 )
int prev[MAX_V];

// vector の出力
template<class T>
void output(vector<T> v){
	for(int i = 0 ; i < v.size() ; i++ ){
		cout << v[i]+1;
		if( i < v.size()-1 )
			cout << " ";
	}
	cout << endl;
}

// 初期化
void init(int n){
	V = n;
	for(int i = 0 ; i < MAX_V ; i++ ){
		G[i].clear();
	}
}

// 始点 s としたダイクストラ法
void dijkstra(int s){
	// greater<P> を指定することで first が小さい順に取り出せる
	priority_queue<P, vector<P>, greater<P> > q;
	fill( d , d+V , INF );
	fill( prev , prev+V , -1 );
	d[s] = 0;
	q.push( P(0,s) );
	
	while( !q.empty() ){
		P p = q.top(); q.pop();
		int v = p.second;
		if( d[v] < p.first ) continue;
		for(int i = 0 ; i < G[v].size() ; i++ ){
			edge e = G[v][i];
			if( d[e.to] > d[v] + e.cost ){
				d[e.to] = d[v] + e.cost;
				q.push( P(d[e.to],e.to) );
				prev[e.to] = v;
			}
		}
	}
}

// 重み cost の辺 (u,v) の追加
void add_edge(int u, int v, int cost){
	edge e( v , cost );
	G[u].push_back( e );
	e.to = u;
	G[v].push_back( e );
}

// 経路復元
vector<int> get_path(int t){
	vector<int> path;
	for( ; t != -1 ; t = prev[t] ){
		path.push_back( t );
	}
	reverse( path.begin() , path.end() );
	return path;
}

int D(int x1, int y1, int x2, int y2){
	return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

int main(){
	int n;
	while( cin >> n ){
		if( n == 0 ) break;
		// 初期化
		init( n );
		
		vector<P> v(n*2);
		for(int i=0 ; i < n*2 ; i++ ){
			v[i] = P(INF,INF);
		}
		for(int i=0 ; i < n ; i++ ){
			int b, x, y;
			cin >> b >> x >> y;
			v[b-1] = P(x,y);
		}
		
		for(int i=0 ; i < v.size() ; i++ ){
			for(int j=i+1 ; j < v.size() ; j++ ){
				int x1 = v[i].first;
				int y1 = v[i].second;
				int x2 = v[j].first;
				int y2 = v[j].second;
				if( x1 == INF || x2 == INF ) continue;
				int dist = D( x1 , y1, x2 , y2 );
				if( dist <= 50*50 ){
					add_edge( i , j , dist );
				}
			}
		}
		
		int m;
		cin >> m;
		for(int i = 0 ; i < m ; i++ ){
			int s,g;
			cin >> s >> g;
			s--; g--;
			dijkstra( s );
			int ans = d[g];
			if( ans == INF ){
				cout << "NA" << endl;
			}else{
				//cout << "path : " << endl;
				vector<int> path = get_path( g );
				//cout << path.size()+1 << endl;
				output( path );
			}
		}
	}
}