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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> b(n), x(n), y(n);
        for(int i = 0; i < n; i++)  cin >> b[i] >> x[i] >> y[i];
        int m;
        cin >> m;
        while(m-- > 0){
            int s, g;
            cin >> s >> g;
            vector<double> dp(n, DBL_MAX);
            vector<int> back(n, -1);
            priority_queue<pair<double, pair<int, int>>> pq;
            int sind, gind;
            for(int i = 0; i < n; i++){
                if(b[i] == s)   sind = i;
                if(b[i] == g)   gind = i;
            }
            pq.push({-0, {sind, -1}});
            while(!pq.empty()){
                auto p = pq.top();  pq.pop();
                double cost = -p.first;
                int pos = p.second.first, par = p.second.second;
                if(dp[pos] <= cost) continue;
                dp[pos] = cost;
                back[pos] = par;
                if(pos == gind) break;
                for(int j = 0; j < n; j++){
                    double dist = sqrt(pow(x[j]-x[pos], 2.0)+pow(y[j]-y[pos], 2.0));
                    if(dist > 50.0) continue;
                    if(dp[j] > cost + dist){
                        pq.push({-(cost+dist), {j, pos}});
                    }
                }
            }
            if(dp[gind] == DBL_MAX){
                cout << "NA" << endl;
                continue;
            }
            vector<int> ans;
            while(gind != -1){
                ans.push_back(b[gind]);
                gind = back[gind];
            }
            reverse(ans.begin(), ans.end());
            for(int i = 0; i < ans.size(); i++){
                cout << ans[i] << " \n"[i+1==ans.size()];
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;

    double d[1000][1000];

int main() {

  const double l_max = 1000000.00;

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    long long int x[1000], y[1000];
    for ( long long int i = 0; i < n; i++ ) {

      long long int b;
      cin >> b;
      b--;
      cin >> x[b] >> y[b];

    }

    for ( long long int i = 0; i < n; i++ ) {
      for ( long long int j = 0; j < n; j++ ) {
	long long int dx = x[i] - x[j];
	long long int dy = y[i] - y[j];
	dx *= dx;
	dy *= dy;
	if ( i == j || dx + dy > 2500 ) {
	  d[i][j] = l_max;
	}else {
	  d[i][j] = sqrt( dx + dy );
	}
      }
    }

    long long int m;
    cin >> m;
    for ( long long int m2 = 0; m2 < m; m2++ ) {

      long long int st, go;
      cin >> st >> go;
      st--;
      go--;

      bool flag[1000] = {};
      double s[1000] = {0.00};
      for ( long long int i = 0; i < n; i++ ) {
	s[i] = l_max;
      }
      s[st] = 0.00;
      long long int b[1000];
      b[go] = -1;

      while( true ) {

	long long int ne = -1;
	for ( long long int i = 0; i < n; i++ ) {
	  if ( flag[i] == false && ( ne == -1 || s[i] < s[ne] ) ) {
	    ne = i;
	  }
	}
	if ( ne == -1 ) break;
	flag[ne] = true;

	for ( long long int i = 0; i < n; i++ ) {
	  if ( s[i] > s[ne] + d[ne][i] ) {
	    s[i] = s[ne] + d[ne][i];
	    b[i] = ne;
	  }
	}

      }

      if ( b[go] == -1 ) {
	cout << "NA" << endl;
	continue;
      }

      vector< long long int > ans;

      long long int k = go;
      while( k != st ) {
	k = b[k];
	ans.push_back(k);
      }

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

    }

  }

  return 0;

}