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;
#define INF 99999999
struct Edge
{
	int b;
	int x;
	int y;
};

vector<int> get_path(int t, int* prev)
{
	vector<int> path;
	while(t != -1)
	{
		path.push_back(t);
		t = prev[t];
	}
	reverse(path.begin(), path.end());
	return(path);
}

vector<int> dijkstra(int src,int dst, const vector<Edge>& edge)
{	
	double d[1001];
	int prev[1001];
	bool used[1001];

	fill((double*)d, (double*)d + 1001, INF);
	fill((bool*)used, (bool*)used + 1001, false);
	fill((int*)prev, (int*)prev + 1001, -1);
	d[src] = 0.0;
	while(true)
	{
		int v = -1;
		for(int u = 0; u < edge.size(); ++u)
		{
			if(!used[u] && (v == -1 || d[u] < d[v]))
			{
				v = u;
			}
		}
		if(v == -1)
		{
			break;
		}
		used[v] = true;
		int srcX = edge[v].x;
		int srcY = edge[v].y;
		for(int u = 0; u < edge.size(); ++u)
		{
			if(u == v)
			{
				continue;
			}
			double cost = sqrt((double)(edge[u].x - srcX) * (double)(edge[u].x - srcX) + (double)(edge[u].y - srcY) * (double)(edge[u].y - srcY));
			if(cost > 50.0)
			{
				continue;
			}
			if(d[u] > d[v] + cost)
			{
				d[u] = d[v] + cost;
				prev[u] = v;
			}
		}
	}
	return get_path(dst, prev);
}

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<Edge> edge;
		for(int i = 0; i < n; ++i)
		{
			int b,x,y;
			cin >> b >> x >> y;
			Edge e = {b,x,y};
			edge.push_back(e);
		}
		int m;
		cin >> m;
		for(int i = 0; i < m; ++i)
		{
			int src, dst;
			cin >> src >> dst;
			int src_idx, dst_idx;
			for(int j = 0; j < edge.size(); ++j)
			{
				if(edge[j].b == src)
				{
					src_idx = j;
				}
				if(edge[j].b == dst)
				{
					dst_idx = j;
				}
			}
			vector<int> route = dijkstra(src_idx,dst_idx,edge);
			if(route[0] == src_idx && route[route.size() - 1] == dst_idx)
			{
				for(int j = 0; j < route.size(); ++j)
				{
					cout << edge[route[j]].b;
					if(j == route.size() - 1)
					{
						cout << endl;
					}
					else
					{
						cout << " ";
					}
				}
			}
			else cout << "NA" << endl; 
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<vector>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,s,g,t;
	while(cin>>n,n){
		double adj[n][n]; rep(i,n)rep(j,n)adj[i][j]=60;
		int x[n],y[n];
		rep(i,n)cin>>t>>x[i]>>y[i];
		rep(i,n)rep(j,i)adj[i][j]=adj[j][i]=hypot(x[i]-x[j],y[i]-y[j]);
		
		cin>>m;
		while(m--){
			cin>>s>>g,s--,g--;
			double cost[n]; rep(i,n)cost[i]=99999999; cost[s]=0;
			vector<vector<int> > path(n); path[s].push_back(s);
			
			vector<int> frontier,next; frontier.reserve(n),next.reserve(n);
			frontier.push_back(s);
			for(;cost[g]==99999999&&!frontier.empty();){
				next.clear();
				rep(i,frontier.size()){
					rep(j,n){
						t=frontier[i];
						if(adj[t][j]<=50&&cost[j]>cost[t]+adj[t][j]){
							cost[j]=cost[t]+adj[t][j];
							path[j]=path[t],path[j].push_back(j);
							next.push_back(j);
						}
					}
				}
				frontier=next;
			}
			if(cost[g]==99999999)cout<<"NA"<<endl;
			else{
				rep(i,path[g].size())cout<<path[g][i]+1<<(i==path[g].size()-1?"\n":" ");
			}
		}
	}
	return 0;
}