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;
using ll = long long;
using pii = pair<int, int>;

const double INF = 1e10;
int n;
int b[110], x[110], y[110];

void solve() {
  for (int i = 0; i < n; i++) {
    cin >> b[i] >> x[i] >> y[i];
    b[i]--;
  }
  double G[110][110], dis[110][110];
  fill_n((double*)G, 110 * 110, INF);  
  fill_n((double*)dis, 110 * 110, INF);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      double d = hypot(x[i] - x[j], y[i] - y[j]);
      if (d > 50) continue;
      G[b[i]][b[j]] = dis[b[i]][b[j]] = d;
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dis[i][k] >= INF || dis[k][j] >= INF) continue;
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int s, g;
    cin >> s >> g;
    s--, g--;
    if (dis[s][g] >= INF) {
      cout << "NA" << endl;
    } else {
      while (s != g) {
        cout << s + 1 << " ";
        for (int j = 0; j < n; j++) {
          if (j != s && G[s][j] + dis[j][g] == dis[s][g]) {
            s = j;
            break;
          }
        }
      }
      cout << g + 1 << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> n, n) {
    solve();
  }  

  return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <math.h>
#define inf 99999.0

using namespace std;

bool check(int *label, int n)
{
	for(int i = 1; i <= n; i++){
		if(label[i] == 0){
			return true;
		}
	}
	
	return false;
}

void dij(float **a, int n, int s, int t)
{
	int *label, current=s, num=1, next, *ne;
	float *cost, min;
	
	cost = (float *)calloc(n+1, sizeof(float));
	label = (int *)calloc(n+1, sizeof(int));
	ne = (int *)calloc(n+1, sizeof(int));
	
	for(int i = 1; i <= n; i++){
		cost[i] = a[current][i];
		if(a[current][i] != inf){
			ne[i] = s;
		}
	}
	label[current] = num++;
	
	while(check(label, n)){
		min = inf;
		for(int i = 1; i <= n; i++){
			if(min >= cost[i] && label[i] == 0){
				min = cost[i];
				next = i;
			}
		}
		label[next] = num++;
		for(int i = 1; i <= n; i++){
			if(label[i] == 0 && cost[i] > (a[next][i]+cost[next])){
				cost[i] = a[next][i] + cost[next];
				ne[i] = next;
			}
		}
		current = next;
	}

	if(ne[t] == 0){
		cout << "NA" << endl;
	} else {
		free(label);
		label = (int *)calloc(n+1, sizeof(int));
		label[0] = t;
		next = ne[t];
		current = 1;
		while(ne[next] != next){
			label[current++] = next;
			next = ne[next];
		}
		label[current] = next;
		for(int i = current; i > 0; i--){
			cout << label[i] << " ";
		}
		cout << t << endl;
	}
	
	free(ne);
	free(cost);
	free(label);
	
	return ;
}

int main(int argc, char **argv)
{
	float **a, *x, *y;
	int n, m, s, t, bn;
		
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (float **)calloc(n+1, sizeof(float));
		x = (float *)calloc(n+1, sizeof(float));
		y = (float *)calloc(n+1, sizeof(float));
		
		for(int i = 1; i <= n; i++){
			a[i] = (float *)calloc(n+1, sizeof(float));
			cin >> bn;
			cin >> x[bn] >> y[bn];
		}
		cin >> m;
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				a[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
				if(a[i][j] > 50.0){
					a[i][j] = inf;
				}
			}
		}
		for(int i = 0; i < m; i++){
			cin >> s >> t;
			dij(a, n, s, t);
		}
		
		for(int i = 0; i <= n; i++){
			free(a[i]);
		}
		free(a);
		free(x);
		free(y);
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

struct Edge{
	int b;
	int x;
	int y;
};

struct Info{
	int from;
	int to;
	int cost;
};

vector<int> get_path(int t,int* prev){
	vector<int> path;
	for(; t!=-1; t = prev[t]) path.push_back(t);
	reverse(path.begin(),path.end());
	return path;
}

vector<int> dijkstra(int src,int dst, const vector<Edge>& edge){

	int* d = new int[edge.size()];
	int* used = new int[edge.size()];
	int* prev = new int[edge.size()];
	fill((int*)d,(int*)d+edge.size(),10000000);
	fill((int*)used,(int*)used+edge.size(),0);
	fill((int*)prev,(int*)prev+edge.size(),-1);

	d[src] = 0;	

	while(true){

		int v = -1;
		for(int u=0;u<edge.size();u++){
			if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}

		if(v == -1) break;
		used[v] = 1;

		int srcX = edge[v].x;
		int srcY = edge[v].y;

		for(int u=0;u<edge.size();u++){
			if(u==v) continue;
			int cost = (edge[u].x - srcX) * (edge[u].x - srcX)
				+ (edge[u].y - srcY) * (edge[u].y - srcY);
			if(cost > 50 * 50) continue;
			if(d[u] > d[v] + cost){
				d[u] = d[v] + cost;
				prev[u] = v;
			}
		}
	}

	return get_path(dst,prev);
}

int main(){
	string str;

	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<Edge> edge;
		for(int i=0;i<n;i++){
			int b,x,y;
			scanf("%d %d %d",&b,&x,&y);
			Edge e = {b,x,y};
			edge.push_back(e);
		}
		int m;
		scanf("%d",&m);

		for(int i=0;i<m;i++){
			int src,dst;
			scanf("%d %d",&src,&dst);
			int src_idx,dst_idx;
			for(int i=0;i<edge.size();i++){
				if(edge[i].b == src){
					src_idx = i;
				}
				if(edge[i].b == dst){
					dst_idx = i;
				}
			}

			vector<int> route = dijkstra(src_idx,dst_idx,edge);

			if(route[0] == src_idx && route[route.size()-1] == dst_idx){
				for(int j=0;j<route.size();j++){
					printf("%d%s",edge[route[j]].b,j == route.size() -1 ? "\n" : " ");
				}
			}
			else cout << "NA" << endl; 
		}
	}
}