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 <stack>
using namespace std;

static const double INF = 1e9;
static const double EPS = 1e-9;

template<class T>
T sqr(T obj) {
	return obj * obj;
}

struct building {
	int b;
	int x;
	int y;

	building(int b_, int x_, int y_) {
		b = b_;
		x = x_;
		y = y_;
	}
};

struct edge {
	int to;
	double cost;
	edge() {}
	edge(int t, double c) {
		to = t;
		cost = c;
	}
};

struct edge1 {
	int from;
	int cur;
	double cost;

	edge1() {}
	edge1(int from_, int cur_, double cost_) {
		from = from_;
		cur = cur_;
		cost = cost_;
	}

	bool operator<(const edge1 & e) const {
		return cost > e.cost;
	}
};

int main() {
	int n;

	while(cin >> n, n) {
		vector<building> v;
		vector<vector<edge> > dist(1024, vector<edge>());
		for(int i = 0; i < n; i++) {
			int b, x, y;
			cin >> b >> x >> y;
			v.push_back(building(b, x, y));
		}

		for(int i = 0; i < v.size(); i++) {
			for(int j = 0; j < v.size(); j++) {
				double d;
				d = sqrt(sqr(v[i].x - v[j].x) + sqr(v[i].y - v[j].y));
				if(d <= 50.0) {
					dist[v[i].b].push_back(edge(v[j].b, d));
				}
			}
		}

		int m;
		cin >> m;
		for(int t = 0; t < m; t++) {
			int s, g;
			cin >> s >> g;
			pair<double,int> cost[1024];
			bool updateflg[1024];
			for(int i = 0; i < 1024; i++) {
				cost[i].first = INF;
				cost[i].second = -1;
				updateflg[i] = true;
			}
			cost[s].first = 0;

			priority_queue<edge1> q;
			q.push(edge1(-1, s, 0));

		//	cout << "dijkstra start" << endl;
			while(!q.empty()) {
				edge1 current;
				current = q.top(); q.pop();
				if(updateflg[current.cur]) {
					cost[current.cur].first = current.cost;
					cost[current.cur].second = current.from;
					updateflg[current.cur] = false;

					for(int i = 0; i < dist[current.cur].size(); i++) {
						if(updateflg[dist[current.cur][i].to]) {
							q.push(edge1(current.cur, dist[current.cur][i].to, current.cost + dist[current.cur][i].cost));
						}
					}
				}
			}
		//	cout << "dijkstra end" << endl;
		//	cout << "cost:" << cost[g].first << " from:" << cost[g].second << endl;

			stack<int> path;
			int indx = g;
			while(cost[indx].second != -1) {
				path.push(indx);
				indx = cost[indx].second;
			}

			if(path.size() == 0)
				cout << "NA" << endl;
			else {
				cout << s;
				while(!path.empty()) {
					cout << " " << path.top();
					path.pop();
				}
				cout << endl;
			}
		}
	}
}