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++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };



int main()
{
	int n;
	while (cin >> n&&n)
	{
		vector<piii> a;
		vector<double> d[1001];
		FOR(i, n)
		{
			piii x; cin >> x.first >> x.second.first >> x.second.second;
			a.push_back(x);
		}
		FOR(i, n)
		{
			FOR(j, n)
			{
				pii x = a[i].second;
				pii y = a[j].second;
				d[i].push_back(sqrt((x.first - y.first)*(x.first - y.first) + (x.second - y.second)*(x.second - y.second)));
			}
		}
		INT(m);
		while (m--)
		{
			typedef pair<double, vi> P;
			INT(start); INT(goal);
			priority_queue< P,vector<P>,greater<P> > que;
			double memo[1001];
			fill(begin(memo), end(memo), 9999999999999.0);
			
			int f;
			for (int i = 0; i < n; i++)
			{
				if (a[i].first == start)f = i;
			}
			memo[f] = 0.0;
			que.push(P(0.0, {f}));
			bool ok = false;
			while (!que.empty())
			{
				P now = que.top(); que.pop();
				int p = now.second.back();
				double k = now.first;
				if(a[p].first==goal)
				{
					ok = true;
					for (int i = 0; i < now.second.size();i++)
					{
						if (i)cout << " ";
						cout << a[now.second[i]].first;
					}
					break;
				}
				for (int i = 0; i < n; i++)
				{
					if (i == p||d[p][i]>50.0)continue;
					if (memo[i] > k + d[p][i])
					{
						memo[i] = k + d[p][i];
						P next = now;
						next.first += d[p][i];
						next.second.push_back(i);
						que.push(next);
					}
				}
			}
			if (!ok)cout << "NA";
			cout << endl;
		}
	}
}

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

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

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

// 頂点数
int V;
// G[u][i] = ノード u に接続している i 番目の edge が返ってくる
vector<edge> G[MAX_V];
// 始点 s からの最短距離 (存在しない場合は INF )
double 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.0;
	q.push( P(0.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, double 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;
}

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

int main(){
	int n;
	while( cin >> n ){
		if( n == 0 ) break;
		// 初期化
		init( n );
		
		vector<pair<int,int> > v(n*2);
		for(int i=0 ; i < n*2 ; i++ ){
			v[i] = pair<int,int>(100000,100000);
		}
		for(int i=0 ; i < n ; i++ ){
			int b, x, y;
			cin >> b >> x >> y;
			v[b-1] = pair<int,int>(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 == 100000 || x2 == 100000 ) continue;
				double dist = D( x1 , y1, x2 , y2 );
				if( dist <= 50.0 ){
					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 );
			}
		}
	}
}