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<cstring>
#include<set>
#include<cmath>

double adjacive[1000][1000];
int field[1000][1000];
int prev[1000];
std::set<int> building;

int input();
void dijkstra(int start);
void output(int start,int goal);

int main()
{
	while(1)
	{
		int n;
		n=input();
		if(n==0)break;
		
		int m;
		std::cin>>m;
		for(int i=0;i<m;i++)
		{
			int bs,bg;
			std::cin>>bs>>bg;
			dijkstra(bs);
			output(bs,bg);
		}
	}
	return 0;
}

int input()
{
	int n;
	std::cin>>n;
	if(n==0)return 0;
	memset(field,0,sizeof(field));
	building.clear();

	for(int i=0;i<1000;i++){for(int j=0;j<1000;j++){adjacive[i][j]=1.0e+10;}}

	for(int i=0;i<n;i++)
	{
		int b,x,y;
		std::cin>>b>>x>>y;
		field[y][x]=b;
		building.insert(b);
	}
	for(int y=0;y<1000;y++)
	{
		for(int x=0;x<1000;x++)
		{
			if(field[y][x]!=0)
			{
				for(int i=-50;i<=50;i++)
				{
					for(int j=-50;j<=50;j++)
					{
						if(i+y>=0&&i+y<1000&&j+x>=0&&j+x<1000&&field[i+y][j+x]!=0&&i*i+j*j<=2500)//genarate adjacive matrix
						{
							adjacive[field[y][x]-1][field[y+i][x+j]-1]=hypot(i,j);
						}
					}
				}
			}
		}
	}
	return n;
}

void dijkstra(int start)
{
	bool visited[1000];
	double cost[1000];
	memset(visited,0,sizeof(visited));
	memset(prev,-1,sizeof(prev));

	for(int i=0;i<1000;i++){cost[i]=1.0e+10;}
	
	cost[start-1]=0;
	while(1)
	{
		int u=-1;
		for(std::set<int>::iterator it=building.begin();it!=building.end();it++)
		{
			if(!visited[*it-1]&&(u==-1||cost[*it-1]<cost[u]))
			{
				u=*it-1;
			}
		}
		if(u==-1)break;
		visited[u]=true;
		for(std::set<int>::iterator it=building.begin();it!=building.end();it++)
		{
			if(cost[*it-1]>cost[u]+adjacive[u][*it-1])
			{
				cost[*it-1]=cost[u]+adjacive[u][*it-1];
				prev[*it-1]=u;
				
			}
		}
	}
}

void output(int start,int goal)
{
	int temp[1000];
	int b=goal-1;
	int i=0;
	bool isNA=true;

	while(prev[b]!=-1)
	{
		temp[i]=b+1;
		i++;
		b=prev[b];
		isNA=false;
	}

	if(isNA)
	{
		std::cout<<"NA"<<std::endl;
	}
	else
	{
		std::cout<<start;
		for(i=i-1;i>=0;i--)
		{
			std::cout<<' '<<temp[i];
		}
		std::cout<<std::endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

#define INF (1 << 20)
#define MAX_V 200

int path[MAX_V];
int cost[MAX_V][MAX_V];
bool used[MAX_V];
int d[MAX_V];

// ?????????O(V^2)

void shortest_path(int s, int V){ // V???????????°
	for(int i = 0; i < V; i++){
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || d[u] < d[add_v])){
				add_v = u;
			}
		} // ??´??°????????????????±????
		//cout << add_v << " ";
		if(add_v == -1){
			break;
		} // ??´??°???????????????????????´????????????
		used[add_v] = true;
		
		for(int u = 0; u < V; u++){
			if(d[add_v] + cost[add_v][u] < d[u]){
				d[u] = d[add_v] + cost[add_v][u];
				path[u] = add_v;
			}
		} // ???????????????????????????????°???????????????´??°
	}
}

void path_track2(int num){
	if(num == -1){
		return;
	}
	path_track2(path[num]);
	cout << num + 1 << " ";
}

void path_track(int num){
	if(num == -1){
		cout << endl;
		return;
	}
	path_track2(path[num]);
	cout << num + 1 << endl;;
}

int main(){
	
	int V, m;
	
	while(true){
		
		cin >> V;
		
		if(V == 0){
			break;
		}
		
		double pos_x[200], pos_y[200];
		
		for(int i = 0; i < V; i++){
			int b;
			double x, y;
			cin >> b >> x >> y;
			pos_x[b - 1] = x;
			pos_y[b - 1] = y;
			path[b - 1] = -1;
		}
		
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				if(i == j){
					cost[i][j] = INF;
				}else if((pos_x[i] - pos_x[j]) * (pos_x[i] - pos_x[j]) + (pos_y[i] - pos_y[j]) * (pos_y[i] - pos_y[j]) <= 2500){
					cost[i][j] = sqrt((pos_x[i] - pos_x[j]) * (pos_x[i] - pos_x[j]) + (pos_y[i] - pos_y[j]) * (pos_y[i] - pos_y[j]));
				}else{
					cost[i][j] = INF;
				}
			}
		}
		
		cin >> m;
		
		for(int loop = 0; loop < m; loop++){
			int s, g;
			cin >> s >> g;
			s--;
			g--;
			shortest_path(s, V);
			
			if(d[g] >= INF){
				cout << "NA" << endl;
			}else{
				path_track(g);
				cout << endl;
			}
		}
		
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>
#include <algorithm>
#include <stack>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;
typedef pair<double, int> R;

struct edge {
	int to;
	double cost;
};

vector<edge> G[1005];
double d[1005];

#define INF 1000000000.0

void dijkstra(int s) {
	priority_queue<R, vector<R>, greater<R> > que;
	fill(d, d+1005, INF);
	d[s] = 0.0;
	que.push(R(0.0, s));

	while (!que.empty()) {
		R p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(R(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		for (int i = 0; i < 1005; i++) {
			G[i].clear();
		}
		vector<Q> data;
		for (int j = 0; j < n; j++) {
		int b, x, y;
		cin >> b >> x >> y;
		data.push_back(Q(b, P(x, y)));
		for (int i = 0; i < data.size()-1; i++) {
			P p = data[i].second;
			edge e;
			e.to = data[i].first;
			e.cost = sqrt((p.first-x)*(p.first-x)+(p.second-y)*(p.second-y));
			if (e.cost > 50.0) {
				continue;
			}
			G[b].push_back(e);
			e.to = b;
			G[data[i].first].push_back(e);
		}
		}
		int m;
		cin >> m;
		int s, g;
		for (int i = 0; i < m; i++) {
			cin >> s >> g;
			dijkstra(s);
			if (d[g] == INF) {
				cout << "NA" << endl;
			} else {
				stack<int> stk;
				stk.push(g);
				while (stk.top() != s) {
					int k = stk.top();
					for (int j = 0; j < G[k].size(); j++) {
						edge e = G[k][j];
						if (d[k] == d[e.to]+e.cost) {
							stk.push(e.to);
							break;
						}
					}
				}
				cout << stk.top();
				stk.pop();
				while (!stk.empty()) {
					cout << ' ' << stk.top();
					stk.pop();
				}
				cout << endl;
			}
		}
	}
	return 0;
}