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()
			}
		}
	}
}

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0155

"""
import sys
from sys import stdin
from math import sqrt
input = stdin.readline


def dijkstra(s, G):
    BLACK, GRAY, WHITE = 0, 1, 2
    d = [float('inf')] * 101
    color = [WHITE] * 101
    p = [-1] * 101

    d[s] = 0
    while True:
        mincost = float('inf')
        # ??\??????????????§??????????????¨?????????????????????u???????????????
        for i in range(101):
            if color[i] != BLACK and d[i] < mincost:  # S????±???????????????????S??¨??\?¶?????????????????????????????????????????°???????????????????
                mincost = d[i]
                u = i  # u??????????????????ID
        if mincost == float('inf'):
            break
        color[u] = BLACK  # ?????????u???S????±???????????????´???
        for v in range(101):
            if color[v] != BLACK and G[u][v] != float('inf'):
                # v????????????????????????????????°??????S???????????£???u????????????????????????????????????????????°??????????????±??§??´??°??????
                if d[u] + G[u][v] < d[v]:
                    d[v] = d[u] + G[u][v]
                    p[v] = u
                    color[v] = GRAY
    return d, p


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break

        G = [[float('inf')] * (100+1) for _ in range(100+1)]
        data = []
        for _ in range(n):
            b, x, y = map(int, input().split(' '))
            data.append([b, x, y])

        for i in range(n):
            b1, x1, y1 = data[i]
            for j in range(n):
                b2, x2, y2 = data[j]
                if b1 == b2:
                    continue
                d = sqrt((x1 - x2)**2 + (y1 - y2)**2)
                if d <= 50.0:
                    G[b1][b2] = d
                    G[b2][b1] = d

        m = int(input())
        for _ in range(m):
            s, g = map(int, input().split(' '))
            if s == g:
                print(s)
                continue
            if (not 1<= s <= 100) or (not 1<= g <= 100):
                print('NA')
                continue
            d, p = dijkstra(s, G)
            if d[g] == float('inf'):
                print('NA')
            else:
                path = [g]
                while p[g] != s:
                    path.append(p[g])
                    g = p[g]
                path.append(s)
                rev = path[::-1]
                print(' '.join(map(str, rev)))


if __name__ == '__main__':
    main(sys.argv[1:])

C++: #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;

#define INF 1000*1000

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int b[n];
      int x[n];
      int y[n];
      for(int i=0;i<n;i++)
	cin>>b[i]>>x[i]>>y[i];

      double edge[n][n];
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  edge[i][j]=INF;

      for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++)
	  {
	    //	    cout<<i<<" "<<j<<"  "<<
	    //  (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<<endl;
	    if((x[i]-x[j])*(x[i]-x[j])+
	       (y[i]-y[j])*(y[i]-y[j])<=2500)
	      {
		double tmp = sqrt((x[i]-x[j])*(x[i]-x[j])+
				 (y[i]-y[j])*(y[i]-y[j]));
		edge[i][j]=tmp;
		edge[j][i]=tmp;
		//cout<<"make_edge "<<i<<" "<<j<<endl;
	      }
	  }
      /*
      for(int i=0;i<n;i++,cout<<endl)
	for(int j=0;j<n;j++)
	  printf("%6.f ",edge[i][j]);
      */
      int m;
      cin>>m;
      for(int i=0;i<m;i++)
	{
	  int s,g;
	  cin>>s>>g;
	  //step,now,keiro
	  priority_queue<pair<double,pair<int,vector<int> > > >qu;
	  for(int i=0;i<n;i++)
	    if(b[i]==s)
	      qu.push(make_pair(0,make_pair(i,vector<int>())));

	  bool closed[n];
	  memset(closed,false,sizeof(closed));
	  vector<int> ans;
	  while(!qu.empty())
	    {
	      double step=-qu.top().first;
	      int now=qu.top().second.first;
	      vector<int> load=qu.top().second.second;
	      qu.pop();
	      load.push_back(b[now]);

	      //	      cout<<"step:"<<step<<" "<<now<<endl;
	      //for(int i=0;i<load.size();i++){cout<<load[i];if(i!=load.size()-1)cout<<" ";else cout<<endl;}


	      if(b[now]==g)
		{
		  ans=load;
		  break;
		}
	      if(closed[now])
		continue;
	      closed[now]=true;
	      for(int i=0;i<n;i++)
		{
		  if(edge[now][i]!=INF && !closed[i])
		    qu.push(make_pair(-(step+edge[now][i]),make_pair(i,load)));
		}
	    }
	  if(ans.empty())
	    cout<<"NA"<<endl;
	  else
	    {
	      for(int i=0;i<ans.size();i++)
		{
		  cout<<ans[i];
		  if(i!=ans.size()-1)
		    cout<<" ";
		  else
		    cout<<endl;
		}
	    }
	}
    }

}