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 <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);   
      if (ans[tg-1]>n) cout <<"NA\n";
      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;
	cout<<endl;
	rep(l,1,k+1)
	  cout<<anss[k-l]+1<<" ";

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

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

void dijkstra(int s,int g){
  ll D[101],from[101];
  from[g]=-1;
  for(int i=0;i<101;i++) D[i]=INF;
  priority_queue<P,vector<P>,greater<P> > Q;
  D[s]=0;
  Q.push(P(0,s));
  while(!Q.empty()){
    P t=Q.top(); Q.pop();
    ll pos=t.second,cost=t.first;
    if(pos==g) break;
    if(D[pos]<cost) continue;

    for(int i=0;i<n;i++){
      if(G[pos][i]==-1)continue;
      if(cost+G[pos][i]<D[i]) {
	Q.push(P(cost+G[pos][i],i));
	D[i]=cost+G[pos][i];
	from[i]=pos;
      }
    }
  }

  if(from[g]==-1){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++){
      double X=(x[i]-x[j]);
      double Y=(y[i]-y[j]);
      double dis=sqrt(X*X+Y*Y);
      if(dis>50)G[i][j]=-1;
      else G[i][j]=G[j][i]=dis;
    }
  
  
  int m;
  cin>>m;
  while(m--){
    int s,g;
    cin>>s>>g;
    dijkstra(s-1,g-1);
  }
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#define INF 100000000
using namespace std;
typedef pair<double,int> P;
struct edge {
  int to;
  double cost;
};
int n,m;
int b[1000],x[1000],y[1000];
double d[1000];
vector<edge> V[1000];
int prev[1000];

double dist(int from, int to) {
  return sqrt((x[to]-x[from])*(x[to]-x[from])+(y[to]-y[from])*(y[to]-y[from]));
}

void dijkstra(int s) {
  priority_queue <P, vector<P>, greater<P> > que;
  for(int i=0;i<n;i++) {
    d[i] = INF;
  }
  d[s] = 0;
  prev[s] = INF;
  que.push(P(0,s));

  while(!que.empty()) {
    P p = que.top();que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i=0;i<V[v].size();i++) {
      edge e = V[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));
      }
    }
  }
}

int main() {

  while(cin >> n) {
    if(n==0) break;
    for(int i=0;i<n;i++) {
      cin >> b[i] >> x[i] >> y[i];
    }

    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
	if(j==i)continue;
	if(double r = dist(i,j) <= 50.0) {
	  edge temp;
	  temp.to = j;
	  temp.cost = r;
	  V[i].push_back(temp);
	  temp.to = i;
	  V[j].push_back(temp);
	}
      }
    }
    cin >> m;
    for(int i=0;i<m;i++) {
      int s,g,ps,pg;
      cin >> ps >> pg;
      for(int i=0;i<n;i++) {
	if(b[i] == ps) s = i;
	else if(b[i] == pg) g = i;
      }
      dijkstra(s);
      if(d[g] != INF) {
	int t = g;
	vector<int> path;
	for(;prev[t] != INF;t = prev[t]) {
	  path.push_back(t);
	}
	path.push_back(s);
	reverse(path.begin(),path.end());
	for(int i=0;i<path.size();i++) {
	  cout << (i==0 ? "":" ") << b[path[i]];
	}
	cout << endl;
	path.clear();
      }
      else
	cout << "NA" << endl;
    }

    for(int i=0;i<n;i++) {
      V[i].clear();
    }
  }
}