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 <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>
#include <complex>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;



struct Point2D { 
	double x, y;
	Point2D (double a=0, double b=0) : x(a), y(b) {}
};

double dist2D(const Point2D& a, const Point2D& b) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); }



typedef double Weight;

struct Edge {
	int from, to;
	Weight weight;
	Edge(int f, int t, double w) : from(f), to(t), weight(w) { }
};

bool operator < (const Edge& e, const Edge& f) {
	return e.weight != f.weight ? e.weight > f.weight : 
			e.from != f.from ? e.from < f.from : e.to < f.to;
}

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

void Dijkstra(const Graph& g, int s, vector<Weight>& dist, vector<int>& prev) {
	int n = (int)g.size();
	dist.assign(n, iINF); dist[s] = 0;
	prev.assign(n, -1);
	priority_queue<Edge> q; q.push(Edge(-2, s, 0));
	
	while (!q.empty()) {
		Edge e = q.top(); q.pop();
		if (prev[e.to] != -1) continue;
		prev[e.to] = e.from;
		
		FOR (it, g[e.to]) {
			if (dist[it->to] > e.weight + it->weight) {
				dist[it->to] = e.weight + it->weight;
				q.push(Edge(it->from, it->to, e.weight + it->weight));
			}
		}
	}
}

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

int main() {

	while (1) {
		int n; cin >> n;
		if (n==0) break;
		
		vector<Point2D> bils(n + 1, Point2D());
		for_(i, 0, n) {
			int b; cin >> b;
			cin >> bils[b].x >> bils[b].y;
		}
		
		Graph graph(n + 1, Edges());
		for_(i, 1, n + 1) {
			for_(j, 1, n + 1) {
				if (i==j) continue;
				Edge e(i, j, dist2D(bils[i], bils[j]));
				if (e.weight <= 50.0) graph[i].pb(e);
			}
		}
		
		int m; cin >> m;
		for_(rep, 0, m) {
			int s, g; cin >> s >> g;
		
			vector<Weight> dist;
			vector<int> prev;
			Dijkstra(graph, s, dist, prev);
		
			if (dist[g] == iINF) cout << "NA" << endl;
			else {
				vector<int> path = buildPath(prev, g);
				int ps = (int)path.sz;
				for_(i, 0, ps) {
					cout << path[i] << " ";
				}
				//cout << path[ps-1] << endl;
			}
		}
	}
	
	
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <complex>
#include <cmath>

using namespace std;

const double EPS = 1e-10;
const double INF = 100000000.0;

typedef complex<double> B;
typedef pair<double, int> P;

map<int, int> idToIdx;
map<int, int> idxToId;
B buildings[1000];
int n, m;
int s, t;
vector<int> G[1000];
int prev[1000];
double dist[1000];
bool used[1000];

priority_queue<P, vector<P>, greater<P> > que;

double getDistance(B a, B b){
  //cout << a << ' ' << b << ' ' << abs(a-b) << endl;
  return abs(a-b);
}

void addEdge(int a, int b){
  G[a].push_back(b);
  G[b].push_back(a);
}

void makeGraph(){
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(getDistance(buildings[i], buildings[j]) < 50.0 + EPS) addEdge(i, j);
    }
  }
}

void dijkstra(){
  fill(dist, dist+n, INF);
  fill(prev, prev+n, -1);
  dist[s] = 0.0;
  que.push(make_pair(0.0, s));

  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;
    for(int i=0;i<G[v].size();i++){
      if(dist[G[v][i]] > dist[v] + getDistance(buildings[v], buildings[G[v][i]])){
	dist[G[v][i]] = dist[v] + getDistance(buildings[v], buildings[G[v][i]]);
	prev[G[v][i]] = v;
	//cout << "!" << getDistance(v, G[v][i]) << endl;
	que.push(make_pair(dist[G[v][i]], G[v][i]));
      }
    }
  }
}

void traverse(){
  vector<int> path;
  if(prev[t] == -1){
    cout << "NA" << endl;
    return;
  }
  for(;t!=-1;t=prev[t]) path.push_back(t);
  reverse(path.begin(), path.end());
  cout << idxToId[path[0]];
  for(int i=1;i<path.size();i++){
    cout << ' ' << idxToId[path[i]];
  }
  cout << endl;
}

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      G[i].clear();
    }
    idToIdx.clear();
    idxToId.clear();
    for(int i=0;i<n;i++){
      int id;
      cin >> id >> buildings[i].real() >> buildings[i].imag();
      idToIdx[id] = i;
      idxToId[i] = id;
    }
    makeGraph();
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> s >> t;
      s = idToIdx[s];
      t = idToIdx[t];
      dijkstra();
      for(int i=0;i<n;i++){
	//cout << dist[i] << endl;
      }
      traverse();
    }
  }
  return 0;
}