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 <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;
	path[s] = -1;
	
	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);
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
double G[101][101];

void dijkstra(int s,int g){
  int used[101]={};
  used[s]=0;
  int from[101]={};
  queue<int> Q;
  Q.push(s);
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    
    for(int i=0;i<n;i++){
      if(G[pos][i]==0||used[i])continue;
      Q.push(i);
      used[i]=1;
      from[i]=pos;
    }
  }

  if(used[g]==0){cout<<"NA"<<endl;return;};

  vector<int> res;
  res.push_back(g);
  int pos=g;
  while(pos!=s){
    pos=from[pos];
    res.push_back(pos);
  }

  for(int i=0;i<res.size();i++){
    if(i) cout<<" ";
    cout<<res[res.size()-1-i]+1;
  }
  cout<<endl;
}


int main(){
  while(cin>>n,n){
    double x[101],y[101];
    for(int i=0;i<n;i++){
      int b;
      cin>>b;
      cin>>x[b-1]>>y[b-1];
    }
    
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++){
	ll X=(x[i]-x[j]);
	ll Y=(y[i]-y[j]);
	ll dis=X*X+Y*Y;
	G[i][j]=G[j][i]=(dis<=50*50);
      }

    int m;
    cin>>m;
    while(m--){
      int s,g;
      cin>>s>>g;
      dijkstra(s-1,g-1);
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<set>
#include<cmath>

double adjacive[1000][1000];
int field[1001][1001];
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;
			bs--;bg--;
			dijkstra(bs);
			output(bs,bg);
		}
	}
	return 0;
}

int input()
{
	int n;
	std::cin>>n;
	if(n==0)return 0;
	memset(field,-1,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;
		b--;
		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]!=-1)
			{
				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]!=-1&&i*i+j*j<=2500)
						{
							adjacive[field[y][x]][field[y+i][x+j]]=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]=0;
	while(1)
	{
		int u=-1;
		for(std::set<int>::iterator it=building.begin();it!=building.end();it++)
		{
			if(!visited[*it]&&(u==-1||cost[*it]<cost[u]))
			{
				u=*it;
			}
		}
		if(u==-1)break;
		visited[u]=true;
		for(std::set<int>::iterator it=building.begin();it!=building.end();it++)
		{
			if(cost[*it]>cost[u]+adjacive[u][*it])
			{
				cost[*it]=cost[u]+adjacive[u][*it];
				prev[*it]=u;
				
			}
		}
	}
}

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

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

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