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 long long ll;
typedef pair<int, int> duo;

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
static const int _mod = 1000000000;
const int INF = 1 << 30;

struct Edge {
  int f, t, w;
  Edge(int f, int t, int w) : f(f), t(t), w(w) {}
  bool operator<(const Edge& e) const {
    return w == e.w ? f < e.f : w > e.w;
  }
};

struct Bldg {
  int x, y, id;
  Bldg(int id, int x, int y) : id(id), x(x), y(y) {}
  int dist(const Bldg& b){
    return sq(x - b.x) + sq(y - b.y);
  }
  bool movable(const Bldg& b){
    return sq(x - b.x) + sq(y - b.y) <= sq(50);
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void shortestPath(const Graph& g, int s, vector<int>& dist, vector<int>& prev){
  int n = g.size();
  dist.assign(n, INF);
  dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ){
    Edge e = Q.top();
    Q.pop();
    if (prev[e.t] != -1) continue;
    prev[e.t] = e.f;
    for (int i = 0; i < g[e.t].size(); i++){
      Edge f = g[e.t][i];
      if (dist[f.t] > e.w + f.w){
        dist[f.t] = e.w + f.w;
        Q.push(Edge(f.f, f.t, e.w + f.w));
      }
    }
  }
}

vector<int> buildPath(const vector<int>& prev, int t){
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u]) path.push_back(u);
  revs(path);
  return path;
}

int main()
{
  int n;
  while (n = in()){
    Graph g(n + 1);
    vector<Bldg> bldgs;
    bldgs.reserve(n);
    for (int i = 0; i < n; i++){
      int id, x, y;
      id = in();
      x = in();
      y = in();
      bldgs.push_back(Bldg(id, x, y));
    }
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        if (i == j) continue;
        if (!bldgs[i].movable(bldgs[j])) continue;
        g[bldgs[i].id].push_back(Edge(bldgs[i].id, bldgs[j].id, bldgs[i].dist(bldgs[j])));
      }
    }
    int m = in();
    for (int i = 0; i < m; i++){
      int s, e;
      s = in();
      e = in();
      vector<int> dist, prev;
      shortestPath(g, s, dist, prev);
      vector<int> path = buildPath(prev, e);
      if (dist[e] != INF) show(path);
      else puts("NA");
    }
  }
  return (0);
}

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;
    for(int i = 0; i < m;i++){
      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;
	for(int j = 0; j < n; j++){
	  if(j == v) continue;
	  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);
	//	for(int i = 0; i < n; i++) cout << pre[i] << " " ;
	//	cout << endl << nums[s] << endl;

	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;
}