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 <bits/stdc++.h>
using namespace std;

struct Edge {
  int src, dst;
  double w;
};

typedef vector<vector<Edge> > Graph;
typedef pair<double,int> Pair;

const double inf = 1e20;

vector<int> dijkstra(int src, int dst, const Graph &g) {
  int n = g.size();
  priority_queue< Pair,vector<Pair>,greater<Pair> > que;
  vector<double> cost(n, inf);
  vector<int> prev(n);
  cost[src] = 0;
  que.push(Pair(0, src));
  while(que.size()) {
    const Pair s = que.top();
    que.pop();
    if(cost[s.second] < s.first) continue;
    if(s.second == dst) {
      vector<int> path;
      int p = dst;
      while(1) {
        path.push_back(p);
        if(p == src) break;
        p = prev[p];
      }
      reverse(path.begin(), path.end());
      return path;
    }
    for(int i = 0; i < g[s.second].size(); ++i) {
      const Edge &e = g[s.second][i];
      Pair t(s.first + e.w, e.dst);
      if(cost[t.second] <= t.first) continue;
      que.push(t);
      cost[t.second] = t.first;
      prev[t.second] = s.second;
    }
  }
  return vector<int>();
}

int main() {
  int n;
  while(cin >> n && n) {
    map<int,int> id, rid;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; ++i) {
      int b;
      cin >> b >> x[i] >> y[i];
      id[b] = i;
      rid[i] = b;
    }
    Graph g(n);
    for(int i = 0; i < n; ++i) {
      for(int j = i+1; j < n; ++j) {
        int cost = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
        if(cost <= 50*50) {
          g[i].push_back((Edge){i,j,sqrt(cost)});
          g[j].push_back((Edge){j,i,sqrt(cost)});
        }
      }
    }
    int m;
    cin >> m;
    while(m--) {
      int src, dst;
      cin >> src >> dst;
      vector<int> v = dijkstra(id[src], id[dst], g);
      if(v.empty()) {
        cout << "NA" << endl;
      } else {
        for(int i = 0; i < v.size(); ++i) {
          if(i) cout << " ";
          cout << rid[v[i]];
        }
        cout << endl;
      }
    }
  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

pii d[2000];
bool used[2000];
double pass[2000][2000];
int n;

void dijk(int s){
    rep(i,2000)d[i]=pii(INF,-1);
    rep(i,2000)used[i]=false;
    d[s]=pii(0,-1);
    
    while (1) {
        int v=-1;
        rep(u,n){
            if( !used[u]&&(v==-1||d[u].first<d[v].first) )v=u;
        }
        
        if(v==-1)break;
        
        used[v]=true;
        
        rep(u,n){
            if( d[u].first>d[v].first+pass[v][u] )
                d[u] = pii( d[v].first+pass[v][u] , v );
        }
    }
}


int main(){
    while(cin>>n){
        if(n==0)break;
        
        rep(i,2000)rep(j,2000) pass[i][j]=INF;
        int b[2000],x[2000],y[2000];
        double res;
        rep(i,n){
            cin>>b[i]>>x[i]>>y[i];
        }
        rep(i,n){
            rep(j,n){
                if(i==j)
                    pass[b[i]-1][b[i]-1]=0;
                else if( ( res=sqrt( (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) ) )<=50+1e-9  ){
                    pass[b[i]-1][b[j]-1]=res;
                    pass[b[j]-1][b[i]-1]=res;
                }
            }
        }
        int m;
        cin>>m;
        rep(i,m){
            int s,g;
            cin>>s>>g;
            s--,g--;
            dijk(s);
            if(d[g].first==INF){cout<<"NA"<<endl;continue;}
            int tmp = g;
            vector<int> ans;
            while(tmp!=s){
                ans.pb(tmp);
                tmp = d[tmp].second;
            }
            ans.pb(s);
            reverse(all(ans));
            rep(i,ans.size()){
                if(i!=0)cout<<" ";
                cout<<ans[i]+1;
            }
            cout<<endl;
        }
    }
}

C++: #include<vector>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const double EPS = 1e-8;
int main(){
	int n,m,s,g,t;
	while(cin>>n,n){
		double adj[n][n]; rep(i,n)adj[i][i]=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+EPS&&cost[j]+EPS>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{
				if(s==g)cout<<s+1<<" "<<s+1<<endl;
				else rep(i,path[g].size())
				cout<<path[g][i]+1<<(i==path[g].size()-1?"\n":" ");
			}
		}
	}
	return 0;
}