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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<double, int> P;
typedef pair<int, int> PII;
static const double EPS = 1e-8;
static const int INF = 1e8;
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
struct edge { 
  int to;
  double cost; 
  edge(int t,double c){
    to = t;
    cost = c;
  }
};
int main(void){
  int d[1001];
  int prev[1001];
  map<int,int> nti;
  int itn[1001];
  int V;
  int m;
  while(cin>>V){
    vector<edge> G[1001];
    if(V==0) break;
    vector<PII> point(V);
    REP(i,V){
      int x,y;
      cin>>itn[i]>>x>>y;
      nti[itn[i]] = i;
      point[i] = PII(x,y);
    }
    REP(i,V)REP(j,V){
      if(i==j) continue;
      double distance = (point[i].first-point[j].first)*(point[i].first-point[j].first) +
        (point[i].second-point[j].second)*(point[i].second-point[j].second);
      if(distance>50*50) continue;
      distance = sqrt(distance);
      G[i].push_back(edge(j,distance));
      G[j].push_back(edge(i,distance));
    }
    cin>>m;
    while(m--){
      int s,g;
      cin>>s>>g;
      s = nti[s]; g = nti[g];
      priority_queue<P, vector<P>, greater<P> > que;
      fill(d,d+V,INF);
      fill(prev,prev+V,-1);
      d[s] = 0;
      que.push(P(0,s));
      while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v]<p.first) continue;
        REP(i,G[v].size()){
          edge e = G[v][i];
          if(d[e.to]>d[v]+e.cost){
            d[e.to] = d[v] + e.cost;
            prev[e.to] = v;
            que.push(P(d[e.to],e.to));
          }
        }
      }
      if(d[g]==INF){
        cout<<"NA"<<endl;
      }else{
        vector<int> ans;
        for(int t = g; t!=-1; t = prev[t]) ans.push_back(itn[t]);
        reverse(ans.begin(),ans.end());
        REP(i,ans.size()){
          if(i) cout<<" ";
          cout<<ans[i];
        }
        cout<<endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <complex>
#include <vector>
#include <utility>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define INF 100000
using namespace std;
typedef complex<double> point; 
void makeroad(vector< vector < pair<int,double> > > &road,point* mapl,int n){
  double tmp;
  rep(i,0,n)
    rep(j,i+1,n)
      if((tmp=abs(mapl[i]-mapl[j]))<=50){
	road[i].push_back(make_pair(j,tmp));

	road[j].push_back(make_pair(i,tmp));
      }
}
int* dijk(const int n, vector< vector< pair<int,double> >  >&list,int s,int g){
  int* keiro;
  int i,j,u;
  double minn;
  double *length;
  bool *check=new bool[n];
  length= new double[n];
  keiro=new int[n];
 
  for(i=0;i<n;i++){
    length[i]=INF;    check[i]=true; keiro[i]=n+1;}
  //rep(i,0,n)
    //cout<<keiro[i]<<'!'<<endl;
  length[s]=0.0;
  while(check[g]){
    minn=(double)INF;


  
    rep(j,0,n)
      if(check[j] && (minn>length[j]) ){
	u=j; minn=length[j];}
    //cout<<u<<"!?"<<endl;
    if(minn==INF) break;
    rep(i,0,list[u].size())
      if(list[u][i].second+length[u]<length[list[u][i].first]){
	length[list[u][i].first]=list[u][i].second+length[u];
	keiro[list[u][i].first]=u;
      }  
    check[u]=false;
  }
  
  return keiro;
}



int main(){
  int n,m,ts,tg,tt;
  int* ans;
  vector<int> anss;
  double ta,tb;
  cin>>n;
  while(n){
    point mapl[n]; 
    rep(i,0,n){
      cin>>tt>>ta>>tb;
      mapl[tt-1]=point(ta,tb);
    }
    //いったんビルの情報を取りましょう
    vector<vector<pair<int,double> > > road(n);//これが道になる
    makeroad(road,mapl,n);//makeroadはmaplでroadを作
    cin>>m;
    rep(i,0,m){
      cin>>ts>>tg;
      ans=dijk(n,road,ts-1,tg-1);   
      cout<<endl;
      if (ans[tg-1]>n) cout <<"NA";
      else{
	tt=tg-1;
	anss.resize(n);
	int k=0;
	anss[k++]=tg-1;
	for(;ans[tt]!=ts-1;tt=ans[tt]){
	  anss[k++]=ans[tt];
	}
	anss[k++]=ts-1;
	
	rep(l,1,k+1)
	  cout<<anss[k-l]+1<<" ";

      }
    }
    cin>>n;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int n, m, b, i, j, x, y, s, g;
vector <pair <int, int> > map(1000);
vector <int> from(1000, 1001);

double dist(int mi, int j) {
  double d =  sqrt(1.0 * (map[j].first - map[mi].first) * (map[j].first - map[mi].first) + (map[j].second - map[mi].second) * (map[j].second - map[mi].second));
  if(d <= 50) return d;
  else        return 100000000;
} 

double dik(){
  int f[1000] = {};
  int mi = s;
  vector <int> cost(1000, 100000000);
  cost[mi] = 0;
  
  for(i = 0; i < 1000; i++) {
    f[mi] = 1;
    
    for(j = 0; j < 1000; j++)
      if(!f[j] && map[j].first != 100000000 && cost[j] > cost[mi] + dist(mi, j)) {
        cost[j] = cost[mi] + dist(mi, j);
        from[j] = mi;
      }
    int min = 200000000;
    for(j = 0; j < 1000; j++)
      if(!f[j] && min > cost[j]) min = cost[mi = j];
  }
  return cost[g];

}


int main(){
  while(cin >> n, n != 0) {
    for(i = 0; i < 1000; i++) {
      map[i].first = 100000000; map[i].second = 100000000;
    }
    
    while(n--){
      cin >> b >> x >> y;  b--;  x--;  y--;
      map[b].first = x; map[b].second = y;
    }
    
    cin >> m;
    while(m--) {
      cin >> s >> g; s--; g--;
      int ans[1000] = {};
      for(i = 0; i < 1000; i++) from[i] = 1001;
      if(dik() != 100000000) {
	
	for(i = g,j = 0; i < 1000; j++){
	  ans[j] = from[i] + 1;
	  i = from[i];
	}
	//	cout << ans[0] << ' ' << ans[1]  <<' '<< ans[2]  << ' ' << ans[3] << endl;
	for(i = j - 2; i >= 0; i--)  cout << ans[i] << ' ';
	cout << g + 1 << endl;
      }
      
      else cout << "NA" << endl;
    }
  }
  return 0;
}