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"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
struct bill {
	int id;
	ld x;
	ld y;
};
typedef ld Weight;
struct Edge {
	int src, dst;
	Weight weight;
	int id;
	Edge(int src_, int dst_, Weight weight_, const int id_) :
		src(src_), dst(dst_), weight(weight_), id(id_) { }
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
	Edge() :src(0), dst(0), weight(0) {

	}
};
vector<int>from;
pair<bool, vector<Weight>> spfa(const int v_num, const vector<vector<Edge>>&es, const int start) {
	vector<Weight>diss(v_num, INT_MAX);
	from = vector<int>(v_num, -1);
	queue<int>que;
	vector<bool>use(v_num);
	vector<int>count(v_num);
	que.emplace(start);
	diss[start] = 0;
	while (!que.empty()) {
		int src(que.front());
		que.pop();
		use[src] = false;
		for (auto e : es[src]) {
			const int d = e.dst;
			if (diss[src] + e.weight < diss[d]) {
				diss[d] = diss[src] + e.weight;
				from[d] = src;
				if (!use[d]) {
					use[d] = true;
					count[d]++;
					if (count[d] >= v_num)return make_pair(false, vector<Weight>());
					que.emplace(d);
				}
			}
		}
	}
	return make_pair(true, diss);
}
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<bill>bs;
		for (int i = 0; i < N; ++i) {
			int b; ld x, y; cin >> b >> x >> y;
			bs.push_back(bill{ b,x,y });
		}
		vector<vector<Edge>>es(N);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i == j)continue;
				ld dx = bs[i].x - bs[j].x;
				ld dy = bs[i].y - bs[j].y;
				ld dis = sqrt((dx*dx) + (dy*dy));
				if (dis- eps <= 50) {
					es[i].push_back(Edge(i, j, dis));
				}
			}
		}
		int M; cin >> M;
		while (M--) {
			int sid, gid;
			{
				int s, g; cin >> s >> g;
				for (int i = 0; i < N; ++i) {
					if (bs[i].id == s)sid = i;
					if (bs[i].id == g)gid = i;
				}
			}
			
			auto p(spfa(N, es, sid));
			if (p.second[gid] < 1e8) {
				vector<int>roots;
				roots.push_back(bs[gid].id);
				int now = gid;
				while (now != sid) {
					now = from[now];
					roots.push_back(bs[now].id);
				}
				reverse(roots.begin(), roots.end());
				for (int i = 0; i < roots.size(); ++i) {
					cout << roots[i];
					if (i == roots.size() - 1) {
						cout << endl;
					}
					else {
						cout << " ";
					}
				}
			}
			else {
				cout << "NA" << endl;
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef double Weight;
const Weight INF = 1e9;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int f, int t, Weight c) :
        src(f), dst(t), weight(c) {}
};
bool operator<(const Edge &a, const Edge &b) {
    return a.weight != b.weight ? a.weight > b.weight :
        a.src != b.src ? a.src < b.src : a.dst < b.dst;
}
bool operator>(const Edge &a, const Edge &b) { return b < a; }

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int n, m;

struct Point {
    double x, y;
    Point() {}
};

void Dijkstra(const Graph &g, int s,
              vector<Weight> &dist, vector<int> &prev) {
    int n = g.size();

    dist.assign(n, INF);
    prev.assign(n, - 1);

    dist[s] = 0;
    priority_queue<Edge> que;  // e < f <=> e.weight > f.weight

    for (que.push(Edge(-2, s, 0)); !que.empty(); ) {
        Edge e = que.top();  que.pop();
        if (prev[e.dst] != -1)
            continue;

        prev[e.dst] = e.src;
        for (auto f = g[e.dst].begin(); f != g[e.dst].end(); ++f) {
            if (dist[f->dst] > e.weight + f->weight) {
                dist[f->dst] = e.weight + f->weight;
                que.push(Edge(f->src, f->dst, e.weight + f->weight));
            }
        }
    }
}

// 始点から頂点tまでの最短経路を返す
vector<int> BuildPath(const vector<int> &prev, int t) {
    vector<int> path;
    for (int u = t; u >= 0; u = prev[u])
        path.push_back(u);
    reverse(path.begin(), path.end());

    return path;
}


int main()
{
    while (cin >> n, n) {
        Graph g(n);
        vector<Weight> dist(n);
        vector<int> prev(n);
        vector<Point> pos(n);

        // Input
        for (int i = 0; i < n; ++i)
            cin >> pos[i].x >> pos[i].x >> pos[i].y;

        // Preprocessing
        for (int i = 0; i < n; ++i)
            for (int j = i + 1; j < n; ++j) {
                double d = (pos[i].x - pos[j].x) * (pos[i].x - pos[j].x)
                    + (pos[i].y - pos[j].y) * (pos[i].y - pos[j].y);
                d = sqrt(d);
                if (d <= 50) {
                    g[i].push_back(Edge(i, j, d));
                    g[j].push_back(Edge(j, i, d));
                }
            }

        cin >> m;
        int s, t;
        for (int i = 0; i < m; ++i) {
            cin >> s >> t;
            --s, --t;

            Dijkstra(g, s, dist, prev);
            if (dist[t] >= INF)
                cout << "NA\n";
            else {
                vector<int> path = BuildPath(prev, t);
                for (size_t i = 0; i < path.size() - 1; ++i)
                    cout << path[i] + 1 << " ";
                cout << path[path.size() - 1] + 1 << '\n';
            }
        }

    }

    return 0;
}