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 <cmath>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
using namespace std;
typedef pair<double,double> P;
typedef pair<double,int> NODE;
#define X first
#define Y second
#define DST first
#define POS second
double ecd(P A,P B){
	A.X = A.X-B.X;
	A.Y = A.Y-B.Y;
	return sqrt(A.X*A.X+A.Y*A.Y);
}


int main(){
	int n,a,b,m;
	double x,y;
	while(cin >> n && n){
		map<int,P> coord;
		map<int,int> from;
		map<int,vector< pair<int,double> > > info;
		map<int,double> memo;
		for(int i=0;i<n;i++){
			cin >> a >> x >> y;
			coord[a] = make_pair(x,y);
		}
		
		for(map<int,P>::iterator it1 = coord.begin();it1 != coord.end();it1++){
			for(map<int,P>::iterator it2 = coord.begin();it2 != coord.end();it2++){
				if(!(ecd((*it1).second,(*it2).second) > 50.0)){
					info[(*it1).first].push_back( make_pair((*it2).first,ecd((*it1).second,(*it2).second)));
				}
			}
			memo[(*it1).first] = (1<<25);
		}

		cin >> m;
		
		for(int i=0;i<m;i++){
			cin >> a >> b;
			vector<int> route;
			priority_queue<NODE,vector<NODE>,greater<NODE> > Q;
			Q.push(make_pair(0,a));
			memo[a]=0;
			from[a]=-1;
			while(Q.size()){
				NODE q = Q.top();Q.pop();
				if(q.POS == b){
					int p = q.POS;
					while(~p){
						route.push_back(p);
						p = from[p];
					}
					break;
				}
				for(int i=0;i<info[q.POS].size();i++){
					if(memo[info[q.POS][i].first] > q.DST + info[q.POS][i].second){
						memo[info[q.POS][i].first] = q.DST + info[q.POS][i].second;
						from[info[q.POS][i].first] = q.POS;
						Q.push(make_pair(memo[info[q.POS][i].first],info[q.POS][i].first));
					}
				}
			}
			if(route.size()){
				reverse(route.begin(),route.end());
				for(int i=0;i<route.size();i++){
					if(i)cout << " ";
					cout << route[i];
				}
			}else{
				cout << "NA";
			}
			cout << endl;
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  const ll INF=1000000000;
  ll n;
  while(1){
    cin >> n;
    if(n==0){
      return 0;
    }
    double dp[110][110];
    ll i,j,k,b[110],x[110],y[110];
    for(i=0;i<n;i++){
      cin >> b[i] >> x[i] >> y[i];
      b[i]--;
    }
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        dp[i][j]=INF;
      }
    }
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        if(sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))<=50){
          dp[b[i]][b[j]]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
      }
    }
    ll z[110][110];
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        z[i][j]=j;
      }
    }
    for(k=0;k<n;k++){
      for(i=0;i<n;i++){
        for(j=0;j<n;j++){
          if(dp[i][j]>dp[i][k]+dp[k][j]){
            dp[i][j]=dp[i][k]+dp[k][j];
            z[i][j]=z[i][k];
          }
        }
      }
    }
    ll m,s,g;
    cin >> m;
    for(i=0;i<m;i++){
      cin >> s >> g;
      s--,g--;
      if(dp[s][g]==INF){
        cout << "NA" << endl;
        continue;
      }
      cout << s+1;
      for(j=s;j!=g;j=z[j][g]){
        cout << ' ' << z[j][g]+1;
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<double, int>P;

int x[200], y[200];
int pre[200];
double d[200];

int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n) {
			int b, xi, yi; scanf("%d%d%d", &b, &xi, &yi); b--;
			x[b] = xi; y[b] = yi;
		}
		vector<P>E[200];
		rep(i, n)for (int j = i + 1; j < n; j++) {
			double f = sqrt((double)(abs(x[i] - x[j])*abs(x[i] - x[j]) + abs(y[i] - y[j])*abs(y[i] - y[j])));
			if (f <= 50.) {
				E[i].push_back(P(f, j));
				E[j].push_back(P(f, i));
			}
		}
		int m; scanf("%d", &m);
		rep(k, m) {
			int s, g; scanf("%d%d", &s, &g); s--; g--;
			fill(d, d + n, INF);
			memset(pre, -1, sizeof(pre));
			priority_queue<P, vector<P>, greater<P>>que;
			d[s] = 0;
			que.push(P(0, s));
			while (!que.empty()) {
				P p = que.top(); que.pop();
				if (d[p.second] != p.first)continue;
				if (p.second == g)break;
				for (P u : E[p.second]) {
					if (d[u.second] > p.first + u.first) {
						d[u.second] = p.first + u.first;
						pre[u.second] = p.second;
						que.push(P(d[u.second], u.second));
					}
				}
			}
			if (d[g] == INF)puts("NA");
			else {
				vector<int>v;
				for (int u = g; ~u; v.push_back(u), u = pre[u]);
				for (int i = v.size() - 1; i >= 0; i--) {
					printf("%d", v[i] + 1);
					if (i)printf(" ");
					else printf("\n");
				}
			}
		}
	}
}