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<cmath>
#include<queue>
#include<vector>
#include<iostream>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	vector<int>			vi;
typedef	pair<double,int>	pdi;

const int inf=1000000000;
int n,id[1000],x[1000],y[1000];
double adj[1000][1000];

bool Dijkstra(int s,int g,int *path)
{
	double d[1000];
	bool visited[1000];
	for(int i=0;i<n;i++)	d[i]=inf,visited[i]=false,path[i]=-1;
	d[s]=0;
	priority_queue<pdi> pq;	pq.push(mp(0,s));
	while(!pq.empty()){
		pdi a=pq.top();	pq.pop();
		double dis=-a.first;
		int u=a.second;
//		if(visited[u])	continue;
		if(u==g)	return true;
		visited[u]=true;
		for(int v=0;v<n;v++){
			if(visited[v])	continue;
			if(dis+adj[u][v]<d[v]){
				d[v]=dis+adj[u][v];
				pq.push(mp(-d[v],v));
				path[v]=u;
			}
		}
	}
	return false;
}

void showPath(int s,int now,int *path,int *id)
{
	if(now==s){ cout<<id[s]; return; }
	showPath(s,path[now],path,id);
	cout<<' '<<id[now];
}

int main()
{
	for(;cin>>n,n;){
		for(int i=0;i<n;i++)	cin>>id[i]>>x[i]>>y[i];

		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	adj[i][j]=(i==j?0:inf);
		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(xx*xx+yy*yy<=50*50)	adj[i][j]=sqrt(xx*xx+yy*yy);
		}

		int m;	cin>>m;
		while(m--){
			int sid,gid;	cin>>sid>>gid;
			int s,g;
			for(int i=0;i<n;i++){
				if(id[i]==sid)	s=i;
				if(id[i]==gid)	g=i;
			}

			int path[1000];
			if(Dijkstra(s,g,path)){
				showPath(s,g,path,id);
				cout<<endl;
			}
			else	cout<<"NA"<<endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<queue>
#define MAX 1000000
#include<complex>
#include<vector>
#include<cmath>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef complex<int> P;
int main(){
	int n,use[1001],m,s,g,now,pre[1001],box[1001],b,x,y;
	double v[1001],d[100][100];
	vector<P> vec;
	map<int,int> na,nb;
	while(cin>>n,n){
		rep(i,n)
		rep(j,n)
		d[i][j]=MAX;
		rep(i,n){
			cin>>b>>x>>y;
			vec.push_back(P(x,y));
			na[i]=b;
			nb[b]=i;
		}
		
		rep(i,vec.size()){
			for(int j=i+1;j<vec.size();j++){
				int p,q;
				y=vec[i].imag();
				x=vec[i].real();
				p=vec[j].imag();
				q=vec[j].real();
				if((x-q)*(x-q)+(y-p)*(y-p)<=2500){
					d[i][j]=(double)sqrt((x-q)*(x-q)+(y-p)*(y-p));
					d[j][i]=(double)sqrt((x-q)*(x-q)+(y-p)*(y-p));
				}
			}
		}
		cin>>m;
		rep(i,m){
			cin>>s>>g;
			s=nb[s];g=nb[g];
			//s=na[s];g=na[g];
			for(int i=0;i<n;i++){
				pre[i]=MAX;
				v[i]=MAX;
				use[i]=0;
			}
			v[s]=0;
			pre[s]=-1;
			now=s;
			bool update=true;
			while(update){
	//			cout<<"now       "<<now<<endl;
				//cout<<now<<endl;
				update=false;
				use[now]=1;
		//		cout<<now<<"   now";
				rep(i,n){
					//cout<<d[now][i]+v[now]<<' '<<v[i];
					if(d[now][i]+v[now]<v[i]){
						v[i]=d[now][i]+v[now];
						pre[i]=now;
						
					}
	//		cout<<' '<<update<<' '<<use[i]<<endl;
				}
				double f=50000;
				rep(i,n){
					if(use[i]==0&&f>v[i]){
						now=i;
						f=v[i];
						update=true;
						
					}
				}
			}
			//cout<<now<<endl;
			if(v[g]==MAX)
			cout<<"NA"<<endl;
			else{
				deque<int> que;
				now=g;
			//	cout<<"         ";
				while(now!=-1){
					que.push_back(na[now]);
					now=pre[now];
				}
				cout<<que.back();
				que.pop_back();
				while(!que.empty()){
						cout<<' ';
					
					cout<<que.back();
					que.pop_back();
				}
				cout<<endl;
				//cout<<d[s][g]<<endl;
			}
//			rep(i,n)
	//		cout<<i<<"         fd"<<v[i]<<endl;
			//cout<<d[8][19]<<endl;
		}
		vec.clear();
		na.clear();
	}
	return 0;
}