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<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		int n, m;
		cin>>n;
		if(n == 0) break;
		vector<P> bil(n);
		vector<vector<double> > p(n, vector<double>(n));
		REP(i, n) {
			ll b, x, y;
			cin>>b>>x>>y;
			--b;
			bil[b] = P(x, y);
		}
		REP(i, n) {
			REP(j, n) {
				if(i == j) continue;
				p[j][i] = p[i][j] = (bil[i].first - bil[j].first) * (bil[i].first - bil[j].first) + (bil[i].second - bil[j].second) * (bil[i].second - bil[j].second);
			}
		}
		cin>>m;
		REP(i, m) {
			int s, g;
			cin>>s>>g;
			--s;
			--g;
			priority_queue<P> que;
			vector<ll> d(n, INF * INF);
			vector<ll> bef(n, INF * INF);
			que.push(P(0, s));
			d[s] = 0;
			while(!que.empty()) {
				P np = que.top();
				que.pop();
				if(d[np.second] != np.first) continue;
				REP(j, n) {
					if(j == np.second) continue;
					if(p[np.second][j] <= 2500) {
						if(d[j] > d[np.second] + sqrt(p[np.second][j])) {
							d[j] = d[np.second] + sqrt(p[np.second][j]);
							que.push(P(d[j], j));
							bef[j] = np.second;
						}
					}
				}
			}
			if(d[g] == INF * INF) cout<<"NA"<<endl;
			else {
				vector<ll> pass;
				pass.pb(g);
				ll np = g;
				while(true) {
					pass.pb(bef[np]);
					if(bef[np] == s) break;
					np = bef[np];
				}
				REP(j, pass.size()) {
					cout<<pass[pass.size() - 1 - j] + 1;
					if(j != pass.size() - 1) cout<<" ";
					else cout<<endl;
				}
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using ld = long double;
const ld eps = 1e-8;
const ld INF = 1e10;
using P = pair<ld, int>;

int main()
{
	int n, m, s, g;
	while (cin >> n, n) {
		vector<vector<P>> G(n);
		vector<ld> x(n), y(n);
		for (int i = 0, b; i < n; i++) {
			cin >> b; b--; cin >> x[b] >> y[b];
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				ld dis = sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
				if (dis <= 50.0 + eps) {
					G[i].push_back(P(dis, j));
					G[j].push_back(P(dis, i));
				}
			}
		}
		cin >> m;
		while (m--) {
			cin >> s >> g; s--; g--;
			vector<ld> d(n, INF);
			d[s] = 0;
			for (int i = 0; i < n - 1; i++) {
				for (int j = 0; j < n; j++) {
					for (auto v : G[j]) {
						d[v.second] = min(d[v.second], d[j] + v.first);
					}
				}
			}
			if (d[g] == INF) {
				cout << "NA" << endl;
				continue;
			}
			vector<int> res;
			int tmp = g; res.push_back(g + 1);
			while (tmp != s) {
				for (auto v : G[tmp]) {
					if (d[v.second] + v.first <= d[tmp] + eps) {
						res.push_back(v.second + 1);
						tmp = v.second;
						break;
					}
				}
			}
			reverse(res.begin(), res.end());
			for (int i = 0; i < (int)res.size(); i++) {
				cout << res[i] << " \n"[i + 1 == (int)res.size()];
			}
		}
	}
	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define dis(a,b) (a)*(a)+(b)*(b)
using namespace std;
void f(vector<int> v,vector<int> &x,int d[][1001],int p[],int c,int e,double s){
  int i;
  vector<int> w=v;
  if(c==e){
    if(p[c]==-1||p[c]>s){
      w.push_back(c);
      x=w;
      p[c]=s;
    }
  }else if(p[c]==-1||p[c]>s){
    w.push_back(c);
    p[c]=s;
    for(i=1;i<1001;i++){
      if(d[c][i]&&d[c][i]<=2500)
	f(w,x,d,p,i,e,s+sqrt(d[c][i]));
    }
  }
  return;
}
int main(){
  int i,j;
  int m,n;
  int p[1001],x[1001],y[1001],d[1001][1001];
  int *b,*e,*g;
  vector<int> v,w;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(d,0,sizeof(d));
    g=new int[n];
    for(i=0;i<n;i++){
      cin>>g[i];
      cin>>x[g[i]]>>y[g[i]];
      for(j=0;j<i;j++){
	d[g[i]][g[j]]=dis(x[g[i]]-x[g[j]],y[g[i]]-y[g[j]]);
	d[g[j]][g[i]]=d[g[i]][g[j]];
      }
    }
    delete[]g;
    cin>>m;
    b=new int[m];
    e=new int[m];
    for(i=0;i<m;i++)
      cin>>b[i]>>e[i];
    for(i=0;i<m;i++){
      v.clear();
      w.clear();
      memset(p,-1,sizeof(p));
      f(v,w,d,p,b[i],e[i],0.0);
      if(w.empty())
	cout<<"NA"<<endl;
      else{
	for(j=0;w.size()-1;j++)
	  cout<<w[j]<<" ";
	cout<<w[j]<<endl;
      }
    }
    delete[]b;
    delete[]e;
  }
  return 0;
}