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<cmath>
#include<stack>
#include<algorithm>
using namespace std;

int main(){
  int n,m,b[1000],x[1000],y[1000],s,g;
  double dis[1001][1001];
  int route[1001][1001];

  while(1){
    cin >> n;
    if(!n)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=i;j<n;j++){
	double d = sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
	if(d>50.0)dis[b[i]][b[j]] = 1e+10;
	else dis[b[i]][b[j]] = d;
	dis[b[j]][b[i]] = dis[b[i]][b[j]];
	route[b[i]][b[j]] = b[i];
	route[b[j]][b[i]] = b[j];
      }
    }

    for(int k=1;k<=n;k++){
      for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
	  if(dis[i][j] > dis[i][k] + dis[k][j]){
	    dis[i][j] = dis[i][k] + dis[k][j];
	    route[i][j] = route[k][j];
	  }
	}
      }
    }
 
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> s >> g;
      if(dis[s][g] >= 1e+10)cout << "NA" << endl;
      else{
	stack<int> a;
	while(s!=g){
	  a.push(g);
	  g = route[s][g];
	}
	cout << s;
	while(a.size()){
	  cout << " " << a.top();
	  a.pop();
	}
	cout << endl;
      }
    }
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep0(i,n) for(i=0;i<(n);i++)
#define repn(i,m,n) for(int i=(m);i<=(n);i++)
#define all(n) n.begin(),n.end()
#define mp make_pair
#define PUTLINE cout<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,1,-1,-1,0};
const int dy[]={0,0,1,-1,1,-1,1,-1,0};

double dis[1010];
string res[1010];
vector<vint> e(1010);

class Pos{
public:
	int n;
	double d;
	string s;
	bool operator>(Pos pos)const{return d>pos.d;}
};

int main() {
	int n;
	int b,x[1010],y[1010];
	while(n=in()){
		memset(x,-1,sizeof(x));
		memset(y,-1,sizeof(y));
		rep(i,1010)e[i].clear();
		rep(i,n){
			cin>>b;
			cin>>x[b]>>y[b];
		}
		repn(i,1,1000){
			if(x[i]==-1)continue;
			repn(j,1,1000){
				if(x[j]==-1)continue;
				if(i==j)continue;
				if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=2500){
					e[i].push_back(j);
				}
			}
		}
		int m=in();
		rep(i,m){
			rep(i,1010)dis[i]=100100100;
			priority_queue<Pos,vector<Pos>,greater<Pos> > que;
			Pos pos;
			pos.n=in();
			pos.d=0;
			stringstream ss;
			ss<<pos.n;
			pos.s=ss.str();
			que.push(pos);
			while(!que.empty()){
				pos=que.top();
				que.pop();
				if(dis[pos.n]<=pos.d)continue;
				dis[pos.n]=pos.d;
				res[pos.n]=pos.s;
				rep(j,e[pos.n].size()){
					Pos next;
					next.n=e[pos.n][j];
					next.d=pos.d+sqrt((double)((x[pos.n]-x[next.n])*(x[pos.n]-x[next.n])+(y[pos.n]-y[next.n])*(y[pos.n]-y[next.n])));
					ss.str("");
					ss<<next.n;
					next.s=pos.s+" "+ss.str();
					que.push(next);
				}
			}
			int g=in();
			if(dis[g]==100100100)cout<<"NA\n";
			else cout<<res[g]<<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    double g[n][n];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) g[i][j] = 100000000;
    int b[n], x[n], y[n];
    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++) {
        int xx = x[i] - x[j], yy = y[i] - y[j];
        if (pow(xx, 2) + pow(yy, 2) <= 2500) g[i][j] = g[j][i] = sqrt(pow(xx, 2) + pow(yy, 2));
      }
    int m;
    cin >> m;
    int s, go;
    for (int i = 0; i < m; i++) {
      cin >> s >> go;
      s--;
      go--;
      vector<int> used(n, false);
      vector<int> gone(n, false);
      vector<double> dist(n, 100000000);
      dist[s] = 0;
      gone[s] = 0;
      while (1) {
        int va = -1;
        for (int j = 0; j < n; j++)
          if (used[j] == false && (va == -1 || dist[va] > dist[j])) va = j;
        if (va == -1) break;
        used[va] = true;
        for (int j = 0; j < n; j++) {
          if (dist[j] >= dist[va] + g[va][j]) gone[j] = va;
          dist[j] = min(dist[j], dist[va] + g[va][j]);
        }
      }
      if (s == go)
        cout << s + 1 << " " << go + 1 << endl;
      else if (dist[go] == 100000000)
        cout << "NA" << endl;
      else {
        int kari = go;
        stack<int> out;
        while (1) {
          out.push(gone[kari] + 1);
          kari = gone[kari];
          if (kari == s) break;
        }
        while (!out.empty()) {
          cout << out.top() << " ";
          out.pop();
        }
        cout << go + 1 << endl;
      }
    }
  }
}