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;
const double eps = 1e-3;

typedef pair<int, int> P;

int main()
{
	int n, m;
	while (cin >> n, n) {
		vector<int> X(n + 1), Y(n + 1);
		for (int i = 0, b; i < n; i++) {
			cin >> b;
			cin >> X[b] >> Y[b];

		}

		vector< vector< pair<double, int> > > bld(n + 1);
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (i != j && (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]) <= 2500) {
					bld[i].push_back(P(sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])), j));
					bld[j].push_back(P(sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])), i));
				}
			}
		}
		cin >> m;
		for (int i = 0, s, g; i < m; i++) {
			cin >> s >> g;
			vector<bool> dec(n + 1, false);
			vector<double> ans(n + 1);
			priority_queue< pair<double, int> > pq;
			pq.push(pair<double, int>(0.0, -s));
			while (!pq.empty()) {
				const int num = -pq.top().second;
				ans[num] = -pq.top().first;
				dec[num] = true;
				for (auto da : bld[num]) {
					if(!dec[da.second])
						pq.push(pair<double, int>(-ans[num] - da.first, -da.second));
				}
				while (!pq.empty() && dec[-pq.top().second]) pq.pop();
			}
			if (dec[g]) {
				int tmp = g;
				vector<int> a;
				a.reserve(n);
				while (tmp != s) {
					for (auto da : bld[tmp]) {
						if (ans[da.second] <= ans[tmp] - da.first + eps && ans[da.second] >= ans[tmp] - da.first - eps) {
							a.push_back(tmp);
							tmp = da.second;
							break;
						}
					}
				}
				cout << s;
				for (int j = a.size() - 1; j >= 0; j--)
					cout << " " << a[j];
				cout << endl;
			}
			else
				cout << "NA" << endl;
		}
	}
	return 0;
}

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-1) {
					cout << path[i] << " ";
				}
				cout << path[ps-1] << endl;
			}
		}
	}
	
	
	
	return 0;
}