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;
typedef long long int ll;
typedef pair<double,ll> mp;
double inf =1e9;
#define EPS 1e-10
struct point{
	double x,y;
	void make(){
		cin>>x>>y;
	}
	point(){};
	point(double x,double y):x(x),y(y){};
	point operator + (point &p) { return point(x+p.x,y+p.y)  ; }
	point operator - (point &p) { return point(x-p.x,y-p.y)  ; }
	double norm() { return x*x+y*y;}
	double abs() { return sqrt(norm()) ;}
};

typedef pair<int,point> mmp;

struct line{
	point s,e;
};

double cross(point a,point b){
	return a.x*b.y-a.y*b.x;
}
double dot(point a,point b){
	return a.x*b.x+a.y*b.y;
}

struct circle{
	point p;
	double r;
	void make(){
		p.make();
		cin>>r;
	}
};

double abs(point a){
	return a.abs();
}
double distance(line l,point p){
	point tmp = l.e-l.s;
	if(dot(tmp,p-l.s) < EPS) return abs(p-l.s);
	if(dot(l.s-l.e,p-l.e) < EPS ) return abs(p-l.e);
	return abs(cross(l.e-l.s,p-l.s ) / abs(l.e-l.s) );
}

typedef pair<mp,int> mpp;
vector<mp> daikus(vector<vector<double> > &g,int s){
	vector<mp> cost(g.size(),mp( inf,g.size() ) );
	vector<bool> used(g.size(),false);
	priority_queue<mpp,vector<mpp>,greater<mpp> > q;
	q.push( mpp(mp(0.0,s),g.size())  );
	cost[s] = mp( 0.0,g.size() );
	while(!q.empty()){
		mp now = q.top().first;
		int prev = q.top().second;
		double nowc = now.first;
		int nn = now.second;
		q.pop();
		if(used[nn])continue;
		used[nn] = true;
		cost[nn] = mp(nowc,prev);
		for(int i=0;i<g.size();i++){
			double nextc = g[nn][i];
			if(nextc>50.0){
				continue;
			}
			if(used[i]) continue;
			q.push(mpp(mp(nowc+nextc,i),nn) );
		}
	}
	return cost;
}

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		vector<mmp> a(n);
		map<int,int> hen;
		for(int i=0;i<n;i++){
			cin>>a[i].first;
			a[i].second.make();
			hen[a[i].first] = i;
		}
		vector<vector<double> > g(n,vector<double>(n,inf) );
		for(int i=0;i<n;i++)for(int j=0;j<n;j++) g[i][j] = abs(a[i].second-a[j].second);
		vector<vector<mp> > cost(n);
		for(int i=0;i<n;i++){
			cost[i] = daikus(g,i);
		}
		int m;
		cin>>m;
		/*for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<cost[i][j].first<<' ';
			}
			cout<<endl;
		}
		cout<<endl;

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<g[i][j]<<' ';
			}
			cout<<endl;
		}
		cout<<endl;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<cost[i][j].second<<' ';
			}
			cout<<endl;
		}
		cout<<endl;
		*/

		for(int i=0;i<m;i++){
			int s,t;
			cin>>s>>t;
			s = hen[s];
			t = hen[t];
			//cout<<"ok"<<s<<' '<<t<<endl;
			vector<int> kei;
			if(cost[s][t].first == inf||cost[s][t].second == n) {
				cout<<"NA"<<endl;
				continue;
			}
			kei.push_back(t);			
			while(t!=s){
		    	//cout<<t<<' '<<cost[s][t].first<<' '<<cost[s][t].second<<endl;
				t = cost[s][t].second;
				kei.push_back(t);
				//cout<<t<<endl;
			}
			//cout<<"ok"<<endl;
			cout<<a[kei[kei.size()-1]].first;
			for(int j=kei.size()-2;j>=0;j--){
				cout<<' '<<a[kei[j]].first;
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <cfloat>
#include <cmath>

struct Building {
	int id;
	int x;
	int y;
	std::vector<int> edge_to;
	std::vector<double> dist_to;
};

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		Building* bldgs = new Building[n];
		std::map<int,int> m_index;
		for (int i=0; i<n; i++) {
			std::cin >> bldgs[i].id >> bldgs[i].x >> bldgs[i].y;
			m_index.insert( std::make_pair(bldgs[i].id, i) );
		}
		for (int i=0; i<n; i++) {
			for (int j=i+1; j<n; j++) {
				int d = (bldgs[i].x - bldgs[j].x) * (bldgs[i].x - bldgs[j].x)
					+ (bldgs[i].y - bldgs[j].y) * (bldgs[i].y - bldgs[j].y);
				if (d <= 2500) {
					bldgs[i].edge_to.push_back(j); bldgs[i].dist_to.push_back(std::sqrt((double)d));
					bldgs[j].edge_to.push_back(i); bldgs[j].dist_to.push_back(std::sqrt((double)d));
				}
			}
		}
		double* dist = new double[n];
		int* p = new int[n];
		int m; std::cin >> m;
		for (int m_=0; m_<m; m_++) {
			int s, g;
			std::cin >> s >> g;
			for (int i=0; i<n; i++) { dist[i] = DBL_MAX; p[i] = -1; }
			int s_index = m_index[s];
			dist[s_index] = 0;
			p[s_index] = s_index;
			for (int k=0; k<n-1; k++) {
				for (int i=0; i<n; i++) {
					for (int j=0; j<bldgs[i].edge_to.size(); j++) {
						int v = bldgs[i].edge_to[j];
						int d = bldgs[i].dist_to[j];
						if (dist[v] - d > dist[i]) {
							dist[v] = dist[i] + d;
							p[v] = i;
						}
					}
				}
			}
			int g_index = m_index[g];
			std::stack<int> st;
			int index = g_index;
			bool reachable = true;
			while (true) {
				st.push(index);
				if (index == s_index) break;
				else if (p[index] == -1) {reachable = false; break; }
				index = p[index];
			}
			if (reachable) {
				std::cout << s; st.pop();
				while (!st.empty()) { std::cout << " " << bldgs[st.top()].id; st.pop(); }
			}
			else std::cout << "NA";
			std::cout << std::endl;
		}
		delete[] dist;
		delete[] p;
		delete[] bldgs;
	}
	return 0;
}