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 <queue>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <map>
#include <cstdlib>
#include <ctime>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<double, int> state;
const int CLK = CLOCKS_PER_SEC;

int s, g;
double memo[100];
int pre[100];
int name[100];
double x[100];
double y[100];

map<int, int> nums;

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

double heuristics(int v){
  return dis(v, nums[g]);
}

int main(){
  int n, m;
  int b;
  int cnt = 0;
  while(cin >> n &&n){
    nums.clear();
    rep(i, n){
      cin >> b >> x[i] >> y[i];
      name[i] = b;
      nums[b] = i;
    }
    cin >> m;
    rep(i, m){
      memset(pre, -1, sizeof(pre));
      fill(memo, memo + 100, 1e10);
      cin >> s >> g;
      memo[nums[s]] = heuristics(nums[s]);
      priority_queue<state, vector<state>, greater<state> > que;
      que.push(state(heuristics(nums[s]), nums[s]));
      
      while(!que.empty()){
	cnt++;
	state st = que.top();
	que.pop();
	int v = st.second;
	double fcost = st.first;
	double gcost = fcost - heuristics(v);
	if(name[v] == g){
	  break;
	}
	if(fcost > memo[v]) continue;
	rep(j, n){
	  double d = dis(v, j);
	  if(d > 50.0) continue;
	  if(memo[j] > gcost + d + heuristics(j)){
	    memo[j] = gcost + d + heuristics(j);
	    pre[j] = v;
	    que.push(state(memo[j], j));
	  }
	}
      }
      if(pre[nums[g]] == -1 && s != g){
	cout << "NA" << endl;
      }else{
	vector<int> res;
	int v = nums[g];
	res.push_back(v);

	while(pre[v] >= 0){
	  v = pre[v];
	  res.push_back(v);
	}

	rep(j, (int)res.size()){
	  if(j != 0) cout << " " ;
	  cout << name[res[res.size() - 1 - j]];
	}
	cout << endl;
      }
    }
  }
  // cout << cnt << endl;
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int b[1000],x[1000],y[1000];

inline double SQ(double x) {return x * x;}

typedef double cost_type;
struct edge {
	int to;
	cost_type cost;
	edge(){}
	edge(int to,cost_type cost) : to(to) ,cost(cost) {}
};

typedef pair<cost_type,int> P;

void dijkstra(int s,vector<P::first_type>& cost_table,vector<vector<edge> >& edges,vector<int>* _prev = NULL){
	
	//init
	cost_table.resize((int)edges.size());
	fill(cost_table.begin(),cost_table.end(),P::first_type(INF));
	if(_prev) _prev->resize((int)edges.size());
	if(_prev) fill(_prev->begin(),_prev->end(),-1);
	
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(0,s));
	cost_table[s] = 0;

	while(!q.empty()){
		P p = q.top(); q.pop();
		int v = p.second;
		if(cost_table[v] < p.first) continue;
		for(int i = 0; i < (int)edges[v].size(); i++){
			edge& e = edges[v][i];
			if(cost_table[e.to] > cost_table[v] + e.cost){
				cost_table[e.to] = cost_table[v] + e.cost;
				if(_prev) (*_prev)[e.to] = v;
				q.push(P(cost_table[e.to],e.to));
			}
		}
	}
}

void get_path(int t,vector<int>& prev,vector<int>& path){
	for(; t != -1; t = prev[t]) path.push_back(t);
	reverse(path.begin(),path.end());
}

int main(){
	int n;
	while(cin>>n,n){
		FOR(i,n) cin>>b[i]>>x[i]>>y[i];
		vector<vector<edge> > edges(n,vector<edge>());
		FOR(i,n) FOR(j,n){
			if(i==j) continue;
			else{
				double d = SQ(x[i]-x[j]) + SQ(y[i]-y[j]);
				if(d <= 2500) edges[i].push_back(edge(j,sqrt(d)));
			}
		}
		map<int,int> mp;
		FOR(i,n) mp[b[i]] = i;

		int n; cin>>n;
		vector<double> costs;
		vector<int> prevs;
		FOR(i,n){
			int s,g; cin>>s>>g;
			s = mp[s],g = mp[g];

			dijkstra(s,costs,edges,&prevs);
			if(prevs[g] == -1){
				puts("NA");
			} else {
			vector<int> path;
				get_path(g,prevs,path);
				FOR(j,sz(path)){
					printf("%d%c",b[path[j]],j == sz(path)-1?'\n':' ');
				}
			}
		}
	}

	return 0;
}