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;
typedef pair<double,int> P;
int n,m,si,ti;
int x[200],y[200];

double d[200];
int pre[200];

int dist(int a,int b){
  int X=x[a]-x[b];
  int Y=y[a]-y[b];
  return X*X+Y*Y;
}

void solve(int si,int ti){
  fill(d,d+200,1e9);
  fill(pre,pre+200,-1);
  
  d[si]=0;
  priority_queue< P , vector<P> , greater<P> > Q;
  Q.push(P(0,si));
  d[si]=0;
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    double cost=p.first;
    int pos=p.second;
    if(cost>d[pos])continue;
    for(int i=1;i<=n;i++){
      if(dist(pos,i)>50*50)continue;
      double ncost=cost+ sqrt( (double)dist(pos,i) );
      if( d[i] > ncost ){
        d[i]=ncost;
        pre[i]=pos;
        Q.push(P(ncost,i));
      }
    }
  }
  vector<int> ans;
  int pos=ti;
  while(pos!=-1){
    ans.push_back(pos);
    pos=pre[pos];
  }
  reverse(ans.begin(),ans.end());

  if(ans.size()==1){
    cout<<"NA"<<endl;
    return;
  }
  
  for(int i=0;i<(int)ans.size();i++){
    if(i)cout<<' ';
    cout<<ans[i];
  }
  cout<<endl;
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;

    for(int i=0;i<n;i++){
      int id;
      cin>>id;
      cin>>x[id]>>y[id];
    }
    
    cin>>m;
    for(int i=0;i<m;i++){
      int si,ti;
      cin>>si>>ti;
      solve(si,ti);
    }
  }
  return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>
#include <math.h>

/*****デバッグ定義*****/
//#define DEBUG
#define INF 10000
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
typedef struct{
	int x;
	int y;
}Field;
Field field[1000];

/*****その他関数置き場*****/
void djikstra(int start,int goal,int buil_num){
	double *dis;
	bool *used;
	int *from;
	int *root;
	int buil;
	int i;
	double distance=0;
	dis = new double [buil_num];
	used = new bool [buil_num];
	from = new int [buil_num];
	root = new int [buil_num];
	for(int i=0;i<buil_num;i++){
		dis[i] = INF;
		used[i] = false;
		from[i] = i;
		root[i] = i;
	}
	dis[start] = 0;
	while(true){
		buil = -1;
		for(int i=0;i<buil_num;i++){
			if(!used[i] && (buil == -1 || dis[i] < dis[buil])){
				buil = i;
			}
		}
		if(buil == -1)	break;
		used[buil] = true;
		//cout << buil+1 << endl;
		for(int i=0;i<buil_num;i++){
			distance = sqrt(((double)field[buil].x - (double)field[i].x)*((double)field[buil].x - (double)field[i].x) + ((double)field[buil].y - (double)field[i].y) * ((double)field[buil].y - (double)field[i].y));
			//cout << i+1 << " " << distance << endl;
			if(dis[i] > dis[buil] + distance && distance <= 50){
				dis[i] = dis[buil] + distance;
				from[i] = buil;
			}
		}
	}
	
	/*for(int i=0;i<buil_num;i++){
		cout  << i+1 << " " << from[i]+1 << " " << dis[i] << endl;
	}
	cout << endl;*/
	int place;
	place = goal;
	i = 0;
	while(place != start){
		root[i] = place;
		//cout << i << " " << root[i] << endl;
		place = from[place];
		i++;
		if(place == from[place])	break;
	}
	root[i] = start;
	//cout << i << " " << root[i] << endl;
	//cout << i << endl;
	if(place != start)	cout << "NA" << endl;
	else{
		while(i != 0){
			cout << root[i]+1 << " ";
			i--;
		}
		cout << root[i]+1 << endl;
	}
	delete dis;
	delete used;
	delete from;
	delete root;
}
/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	/*****処理部*****/
	int buil_num;
	int order_num;
	while(1){
		cin >> buil_num;
		if(buil_num == 0)	break;
		for(int i=0;i<buil_num;i++){
			int b_n,x_ax,y_ax;
			cin >> b_n >> x_ax >> y_ax;
			field[b_n-1].x = x_ax;
			field[b_n-1].y = y_ax;
		}
		cin >> order_num;
		for(int i=0;i<order_num;i++){
			int start,goal;
			cin >> start >> goal;
			djikstra(start-1,goal-1,buil_num);
		}
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

const double EPS = 1e-6;

struct Building{
	int x, y;
	Building(){
		x = -1; y = -1;
	}
};

struct Edge{
	int to;
	double cost;
	Edge(){}
	Edge(const int &_to, const double &_cost){
		to = _to; cost = _cost;
	}
};

struct Data{
	int n;
	double cost;
	Data(){}
	Data(const int &_n, const double &_cost){
		n = _n; cost = _cost;
	}
	bool operator < (const Data &a) const{
		return cost > a.cost;
	}
};

double GetDistance(const Building &b1, const Building &b2){
	double dx = b1.x - b2.x, dy = b1.y - b2.y;
	return sqrt(dx*dx + dy*dy);
}

vector<Edge> e[1000];
Building v[1000];
priority_queue<Data> pq;

int main(){
	int N, M, B, S, G;

	while(cin >> N, N){
		for(int i = 0; i < 1000; i++) e[i].clear();

		for(int i = 0; i < N; i++){
			cin >> B; B--;
			cin >> v[B].x >> v[B].y;
		}

		for(int i = 0; i < 1000; i++){
			for(int j = i+1; j < 1000; j++){
				if(v[i].x == -1 || v[j].x == -1 || i == j) continue;
				double dist = GetDistance(v[i], v[j]);
				if(dist <= 50){
					e[i].push_back( Edge(j, dist) );
					e[j].push_back( Edge(i, dist) );
				}
			}
		}

		cin >> M;
		for(int j = 0; j < M; j++){
			cin >> S >> G; S--; G--;

			Data pq_top;
			pq.push( Data(S, 0) );
			double memo[1000];
			fill_n(memo, 1000, -1);
			bool na = true;

			while( !pq.empty() ) pq.pop();
			while( !pq.empty() ){
				pq_top = pq.top(); pq.pop();
			
				if(memo[pq_top.n] > -0.5) continue;
				memo[pq_top.n] = pq_top.cost;
				if(pq_top.n == G){
					na = false; break;
				}

				for(int i = 0; i < e[pq_top.n].size(); i++){
					pq.push( Data( e[pq_top.n][i].to, pq_top.cost + e[pq_top.n][i].cost ) );
				}
			}

			if(na){
				puts("NA"); break;
			}

			stack<int> ans;
			while(true){
				ans.push(G);
				if(G == S) break;
				for(int i = 0; i < e[G].size(); i++){
					if( abs(memo[G] - memo[ e[G][i].to ] - e[G][i].cost) < EPS){
						G = e[G][i].to; break;
					}
				}
			}
		
			printf("%d", ans.top()+1 ); ans.pop();
			while( !ans.empty() ){
				printf(" %d", ans.top()+1 ); ans.pop();
			}puts("");
		}
	}
	return 0;
}