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 <iostream>
#include <sstream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

const double eps = 1e-9;
const double inf = (double)(1<<24);
const int size = 1001;
int n;
int b[size], x[size], y[size];
bool p[size][size];
double c[size][size];

int CN[size][size];
int CNcnt[size];

double mc[size];
int prev[size];
typedef pair <double, int> Node;
typedef priority_queue <Node, vector<Node>, greater<Node> > QUEUE;

bool big_equal( double a, double b )
{
    return fabs( a - b ) < eps ? true : a < b;
}

double getdist( int x1, int y1, int x2, int y2 )
{
    double X = x2 - x1, Y = y2 - y1;
    return sqrt( X * X + Y * Y );
}

string solve( int s, int g )
{
    QUEUE Q;
    Node start( 0.0, s );
    Q.push( start );
    mc[s] = 0.0;

    while ( !Q.empty() ) {
        Node node = Q.top();
        Q.pop();

        double cost = node.first;
        int ind = node.second;

        if ( ind == g ) {
            vector <int> list;
            list.push_back( g+1 );
            int t = prev[g];
            while ( t != -1 ) {
                list.push_back( t+1 );
                t = prev[t];
            }
            reverse( list.begin(), list.end() );
            ostringstream os;
            for ( vector <int> ::iterator it = list.begin(); it != list.end(); it++ ) {
                os << *it;
                if ( it + 1 != list.end() ) os << " ";
            }
            return os.str();
        }

        for ( int i = 0; i < CNcnt[ind]; i++ ) {
            int next_ind = CN[ind][i];
            double next_cost = node.first + c[ind][next_ind];
            if ( big_equal( mc[next_ind], next_cost ) ) {
                continue;
            }
            mc[next_ind] = next_cost;
            prev[next_ind] = ind;
            Node next_node( next_cost, next_ind );
            Q.push( next_node );
        }
    }

    return "NA";
}

int main()
{
    while ( cin >> n && n ) {
        // init
        for ( int i = 0; i < n; i++ ) {
            CNcnt[i] = 0;
            for ( int j = 0; j < n; j++ ) {
                p[i][j] = false;
                c[i][j] = inf;
            }
        }

        // input
        for ( int i = 0; i < n; i++ ) {
            cin >> b[i];
            int ind = b[i] - 1;
            cin >> x[ind] >> y[ind];
        }

        // proc
        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                if ( i == j ) continue;
                c[i][j] = getdist( x[i], y[i], x[j], y[j] );
                if ( big_equal( c[i][j], 50.0 ) ) {
                    p[i][j] = true;
                    CN[i][CNcnt[i]++] = j;
                }
            }
        }

        int m;
        cin >> m;
        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                mc[j] = inf;
                prev[j] = -1;
            }

            int s, g;
            cin >> s >> g;
            cout << solve( s-1, g-1 ) << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
#define INF 1e10
#define EPS 1e-10
#define EQ(a,b) (fabs((a)-(b))<EPS)

double dist[1000][1000];
int id[1000],x[1000],y[1000];

double Distance(int i,int j){
	return sqrt((double)(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}


int main(){
	int n;
	while(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++){
			double d=Distance(i,j);
			dist[i][j]=(d<50+EPS?d:INF);
		}
		for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
			dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		int m;
		cin>>m;
		for(int i=0;i<m;i++){
			int s,g;
			cin>>s>>g;
			for(int i=0;i<n;i++){
				if(s==id[i]){
					s=i;
					break;
				}
			}
			for(int i=0;i<n;i++){
				if(g==id[i]){
					g=i;
					break;
				}
			}
			if(dist[s][g]==INF){
				cout<<"NA\n";
				continue;
			}
			stack<int> st;
			int v=g;
			while(v!=s){
				for(int i=0;i<n;i++){
					if(i==v)continue;
					if(EQ(dist[s][v],dist[s][i]+Distance(i,v))){
						st.push(v);
						v=i;
						break;
					}
				}
			}
			cout<<id[s];
			while(!st.empty()){
				cout<<' '<<id[st.top()];
				st.pop();
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int N=1001;
int F(double x,double y){return fabs(x-y)<1e-9;}
int main()
{
	int n,m,i,j,b,x,y,s,g,X[N],Y[N];
	static double D[N][N],V=1e10,t;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)scanf("%d%d%d",&b,&x,&y),X[b]=x,Y[b]=y;
		for(i=1;i<=n;++i)for(j=1;j<=n;++j)D[i][j]=D[j][i]=hypot(X[i]-X[j],Y[i]-Y[j]);
		for(scanf("%d",&m);m--;)
		{
			scanf("%d%d",&s,&g);
			typedef pair<double,int>P;
			P p;
			priority_queue<P>q;
			double d[N];
			fill(d,d+N,V);
			q.push(P(0,s));
			d[s]=0;
			while(!q.empty())
			{
				p=q.top();q.pop();
				for(i=1;i<=n;++i)
					if(t=D[p.second][i],t<=50&&d[p.second]+t<d[i])
						d[i]=d[p.second]+t,q.push(P(p.first-t,i));
			}
			if(d[g]==V)puts("NA");
			else
			{
				vector<int>v(1,g);
				for(i=g;i-s;v.push_back(i=j))for(j=1;j<=n;++j)
					if(i-j&&F(d[i],D[i][j]+d[j]))break;
				for(i=v.size()-1;i>=0;--i)printf("%d%c",v[i],i?' ':'\n');
			}
		}
	}
	return 0;
}