Language: C++

#include<cstdio>
#include<string.h>

using namespace std;

#define MAX 51

int xy[MAX][MAX];
int cost[MAX][MAX][MAX][MAX];
int X,Y;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct state{
  int tx;
  int ty;
  int kx;
  int ky;
  int co;
  state(){}
  state(int tx,int ty,int kx,int ky,int co):
    tx(tx),ty(ty),kx(kx),ky(ky),co(co){}
};

int solve(int tx,int ty,int kx,int ky){

  memset(cost,101,sizeof(cost));

  queue<state> q;
  q.push( state(tx,ty,kx,ky,0) );

  while( !q.empty() ){
    state p=q.front();
    q.pop();

    if(p.co==100){
      break;
    }

    tx=p.tx;
    ty=p.ty;
    kx=p.kx;
    ky=p.ky;

    for(int i=0;i<4;i++){
      
      if(kx+dx[i]*-1 < 0 || ky+dy[i]*-1 <0 || kx+dx[i]*-1 >= X || ty+dy[i]*-1 >= Y || 
	 tx+dx[i] < 0 || ty+dy[i] <0 || tx+dx[i] >= X || ty+dy[i] >= Y )
	continue;

      cost[tx][ty][kx][ky]=p.co;

      if( cost[tx+dx[i]][ty+dy[i]][kx+dx[i]*-1][ky+dy[i]*-1] < p.co)
	continue;

      if( xy[ty+dy[i]][tx+dx[i]]==1 || xy[ky+dy[i]*-1][kx+dx[i]*-1]==1 )
	continue;
      
      if(tx+dx[i] == kx+dx[i]*-1 && ty+dy[i] == ky+dy[i]*-1)
	return p.co+1;

      q.push( state(tx+dx[i],ty+dy[i],kx+dx[i]*-1,ky+dy[i]*-1,p.co+1) );

    }
  }
  return -1;
} 

main(){
  
  int i,j;
  int kx,ky,tx,ty;
  int n;

  while(1){
    
    cin >> X >> Y;

    if(X==0 && Y==0) break;
    
    cin >> tx >> ty;
    cin >> kx >> ky;
    
    for(i=0;i<Y;i++){
      for(j=0;j<X;j++){
	cin >> xy[i][j];
      }
    }
    
    n=solve(tx-1,ty-1,kx-1,ky-1);
    
    if(n==-1)
      cout << "NA" << endl;
    else
      cout << n << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int solve(int, int, int, int)':
a.cc:30:3: error: 'queue' was not declared in this scope
   30 |   queue<state> q;
      |   ^~~~~
a.cc:3:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    2 | #include<string.h>
  +++ |+#include <queue>
    3 | 
a.cc:30:14: error: expected primary-expression before '>' token
   30 |   queue<state> q;
      |              ^
a.cc:30:16: error: 'q' was not declared in this scope
   30 |   queue<state> q;
      |                ^
a.cc: At global scope:
a.cc:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:78:5: error: 'cin' was not declared in this scope
   78 |     cin >> X >> Y;
      |     ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include<string.h>
  +++ |+#include <iostream>
    3 | 
a.cc:94:7: error: 'cout' was not declared in this scope
   94 |       cout << "NA" << endl;
      |       ^~~~
a.cc:94:7: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:94:23: error: 'endl' was not declared in this scope
   94 |       cout << "NA" << endl;
      |                       ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include<string.h>
  +++ |+#include <ostream>
    3 | 
a.cc:96:7: error: 'cout' was not declared in this scope
   96 |       cout << n << endl;
      |       ^~~~
a.cc:96:7: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:96:20: error: 'endl' was not declared in this scope
   96 |       cout << n << endl;
      |                    ^~~~
a.cc:96:20: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'