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;

#define SQ(a) ((a)*(a))

struct Edge {
	int to;
	double cost;
	Edge(int to, double cost): to(to), cost(cost){}
};

struct State {
	int n;
	double sum;
	State(int n, int sum): n(n), sum(sum){}
	bool operator < (const State &t) const {
		return sum > t.sum;
	}
};

int x[1000], y[1000];
double d[1000];
int pre[1000];
vector<Edge> g[1000];

int btoi[1001];
int itob[1000];

vector<int> rec(int start, int goal)
{
	vector<int> res;
	for (int e = goal; e != -1; e = pre[e]){
		res.push_back(itob[e]);
	}
	reverse(res.begin(), res.end());
	if (res[0] != itob[start] || res[res.size() - 1] != itob[goal]){
		return vector<int>();
	}
	return res;
}

void solve(int start, int goal)
{
	fill(d, d + 1000, 1e50);
	memset(pre, -1, sizeof(pre));
	
	d[start] = 0.0;
	priority_queue<State> que;
	for (que.push(State(start, 0.0)); que.size(); que.pop()){
		State st = que.top();
		if (d[st.n] < st.sum) continue;
		for (int v = 0; v < g[st.n].size(); v++){
			Edge &e = g[st.n][v];
			if (d[e.to] < st.sum + e.cost) continue;
			d[e.to] = st.sum + e.cost;
			pre[e.to] = st.n;
			que.push(State(e.to, st.sum + e.cost));
		}
	}
	
	vector<int> route = rec(start, goal);
	if (route.size() == 0){
		puts("NA");
		return;
	}
	for (int i = 0; i < route.size(); i++){
		if (i) printf(" ");
		printf("%d", route[i]);
	}
	puts("");
}

int main()
{
	int n;
	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++) g[i].clear();
		for (int i = 0; i < n; i++){
			int b;
			scanf("%d", &b);
			btoi[b] = i;
			itob[i] = b;
			scanf("%d %d", &x[i], &y[i]);
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				if (i == j) continue;
				double dist = sqrt(SQ(x[i] - x[j]) + SQ(y[i] - y[j]));
				if (dist > 50) continue;
				g[i].push_back(Edge(j, dist));
				g[j].push_back(Edge(i, dist));
			}
		}
		
		int m;
		scanf("%d", &m);
		for (int i = 0; i < m; i++){
			int start, goal;
			scanf("%d %d", &start, &goal);
			solve(btoi[start], btoi[goal]);
		}
	}
	
	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;
}