Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cassert>

using namespace std;

const int MAX_V = 1001;
const int INF   = INT_MAX;

struct Edge {
  int to;
  int cost;
};

int          V;
vector<Edge> G[MAX_V];
int          d[MAX_V];
int          prev[MAX_V];

void dijkstra(int s) {
  typedef pair<int, int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, INF);
  fill(prev, prev + V, -1);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P   p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < (int)G[v].size(); i++) {
      Edge e = G[v][i];

      if (d[e.to] > d[v] + e.cost) {
        d[e.to]    = d[v] + e.cost;
        prev[e.to] = v;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

vector<int> get_path(int t) {
  vector<int> path;

  for (; t != -1; t = prev[t]) {
    path.push_back(t);
  }
  reverse(path.begin(), path.end());
  return path;
}


struct Building {
  int x;
  int y;
};

int distance2(Building *b1, Building *b2) {
  int dx = b1->x - b2->x;
  int dy = b1->y - b2->y;
  return dx * dx + dy * dy;
}

int name[MAX_V];
int rname[MAX_V];
Building building[MAX_V];

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    V = n;

    for (int i = 0; i < n; i++) {
      G[i].clear();
    }
    for (int i = 0; i < n; i++) {
      int b;
      cin >> b;
      name[i] = b;
      rname[b] = i;
      cin >> building[i].x >> building[i].y;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        Building *b1 = building + i;
        Building *b2 = building + j;
        int       d2 = distance2(b1, b2);

        if (d2 <= 50 * 50) {
          int d1 = sqrt(d2);
          Edge e1 = {j, d1};
          G[i].push_back(e1);
          Edge e2 = {i, d1};
          G[j].push_back(e2);
        }
      }
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int s;
      int g;
      cin >> s >> g;
      dijkstra(rname[s]);
      if (d[rname[g]] == INF) {
        cout << "NA" << endl;
      } else {
        vector<int> path = get_path(rname[g]);
        for (int j = 0; j < (int)path.size(); j++) {
          cout << name[path[j]];
          if (j < (int)path.size() - 1)
            cout << " ";
        }
        cout << endl;
      }
    }
  }
  return 0;
}

Compiler output:
a.cc:16:19: error: 'INT_MAX' was not declared in this scope
   16 | const int INF   = INT_MAX;
      |                   ^~~~~~~
a.cc:12:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   11 | #include <cassert>
  +++ |+#include <climits>
   12 | 
a.cc: In function 'void dijkstra(int)':
a.cc:32:8: error: reference to 'prev' is ambiguous
   32 |   fill(prev, prev + V, -1);
      |        ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:26:14: note:                 'int prev [1001]'
   26 | int          prev[MAX_V];
      |              ^~~~
a.cc:32:14: error: reference to 'prev' is ambiguous
   32 |   fill(prev, prev + V, -1);
      |              ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:26:14: note:                 'int prev [1001]'
   26 | int          prev[MAX_V];
      |              ^~~~
a.cc:45:9: error: reference to 'prev' is ambiguous
   45 |         prev[e.to] = v;
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:26:14: note:                 'int prev [1001]'
   26 | int          prev[MAX_V];
      |              ^~~~
a.cc: In function 'std::vector<int> get_path(int)':
a.cc:55:23: error: reference to 'prev' is ambiguous
   55 |   for (; t != -1; t = prev[t]) {
      |                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:26:14: note:                 'int prev [1001]'
   26 | int          prev[MAX_V];
      |              ^~~~