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 <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

class Node{
public:
	int id;
	vector< int > e_to;
	vector< double> e_cost;
	int pre;
    
	bool def;
	int min_cost;
    
    Node(){
    	def = false;
		min_cost = -1;
		pre = -1;
	}
};

bool operator==(const Node& ot1, const Node& ot2){
	return ot1.min_cost == ot2.min_cost;
}
bool operator!=(const Node& ot1, const Node& ot2){
	return !(ot1 == ot2);
}
bool operator<(const Node& ot1, const Node& ot2){
	return ot1.min_cost < ot2.min_cost;
}
bool operator>(const Node& ot1, const Node& ot2){
	return ot1.min_cost > ot2.min_cost;
}
bool operator<=(const Node& ot1, const Node& ot2){
	return !(ot1 > ot2);
}
bool operator>=(const Node& ot1, const Node& ot2){
	return !(ot1 < ot2);
}

class Dijkstra{
	priority_queue< Node, vector< Node >, greater< Node > > que;
	vector< Node > nodes;
public:
	void Init(int node_num){
		nodes.clear();
		nodes.resize(node_num);
		for(int i = 0; i < node_num; ++i){
			nodes[i] = Node();
		}
	}

	void Put(int id, int to, double cost){
		nodes[id].id = id;
		nodes[id].e_to.push_back(to);
		nodes[id].e_cost.push_back(cost);
	}
	
    double Run(int s, int t){
		for(vector< Node >::iterator it = nodes.begin(); it != nodes.end(); ++it){
			it->min_cost = -1;
			it->def = false;
			it->pre = -1;
		}
		
		nodes[s].min_cost = 0;
		que.push(nodes[s]);

		while(!que.empty()){
			Node def_node = que.top();
			que.pop();
			
			if(def_node.def)continue;
			
			def_node.def = true;
			
			for(int i = 0; i < def_node.e_to.size(); ++i){
				int to = def_node.e_to[i];
				double cost = def_node.min_cost + def_node.e_cost[i];
				
				if(nodes[to].min_cost < 0 || cost < nodes[to].min_cost){
					nodes[to].min_cost = cost;
					nodes[to].pre = def_node.id;
					que.push(nodes[to]);
				}
			}
		}
		return nodes[t].min_cost;
	}

	void GetRoute(int t, vector< int > *route){
		int id = t;
		
		while(1){
			route->push_back(id);
			id = nodes[id].pre;
			
			if(nodes[id].pre == -1){
				route->push_back(id);
				break;
			}
		}
	}
};

int main(){
	int n, m, b, s, g;
	double cost;
	vector< int > x, y, route;
	Dijkstra dst;
	
	while(cin >> n, n){
		dst.Init(n);
		x.resize(n);
		y.resize(n);
		for(int i = 0; i < n; ++i){
			cin >> b;
			cin >> x[b - 1] >> y[b - 1];
		}
		
		for(int i = 0; i < n; ++i){
			for(int j = i + 1; j < n; ++j){
				if((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) <= 2500){
					dst.Put(i, j, sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])));
					dst.Put(j, i, sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])));
				}
			}
		}
		
		cin >> m;
		for(int i = 0; i < m; ++i){
			route.clear();
			cin >> s >> g;
			cost = dst.Run(s - 1, g - 1);
			if(cost < 0){
				cout << "NA" << endl;
			}else{
				dst.GetRoute(g - 1, &route);
				reverse(route.begin(), route.end());
				for(int j = 0; j < route.size(); ++j){
					cout << (j ? " " : "") << route[j] + 1;
				}
				cout << endl;
			}
		}
	}
    return 0;
}