Language: C++

#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 

int main() {
  int h,w,a,b,c,dd;
  cin >> h >> w >> a >> b >> c >> dd;
  string st;
  char [h+1][w+1];
  
  for(int i = 1;i<h+1;i++){
      cin >> st;
    for(int j = 1;j<w+1;j++){
      //cout << i << " " << j << endl;
      s[i][j] = st[j-1];
    }
  }
  int m[h+1][w+1] = {};
  pair<int,int> tmp;
  vector<vector<int>>dx = {{1,0},{0,1},{-1,0},{0,-1}};
  int nx,ny;
  int ct =0;
  deque<pair<int,int>> d;
  for(int i = 1;i<h+1;i++){
    for(int j = 1;j<w+1;j++){
      d.clear();
      tmp = make_pair(i,j);
      d.push_front(tmp);
      if(m[i][j] == 0 && s[i][j] == '.'){
        ct++;
        m[i][j] = ct;
        while(!d.empty()){
          tmp = d.back();
          d.pop_back();
          for(int k = 0; k < 4;k++){
            nx = tmp.first + dx[k][0];
	        ny = tmp.second + dx[k][1];
            if(nx >0 && nx <h+1 && ny > 0 && ny <w+1){
              if(s[nx][ny] != '#' &&  m[nx][ny] ==0){
                m[nx][ny] = ct;
                d.push_front(make_pair(nx,ny));
              }
            }
          }
        }
      }
      //cout << i << " " << j << " " << m[i][j] << endl;
    }
  }
  int G[ct+1][ct+1] = {};
  for(int i = 1;i<h+1;i++){
    for(int j = 1;j<w+1;j++){
      for(int x = -2;x<=2;x++){
        for(int y = -2;y<=2;y++){
          nx = i+x;
          ny = j+y;
          //if(nx == 3 && ny == 2 && i == 1 && j == 2){cout << m[nx][ny] << " " <<  m[i][j];}
          if(nx >0 && nx <h+1 && ny > 0 && ny <w+1){
            if(s[nx][ny] != '#' && s[i][j] != '#' && m[nx][ny] != m[i][j]){
              //cout << m[nx][ny] << " " << m[i][j] << endl;
              G[m[nx][ny]][m[i][j]] = 1;
              G[m[i][j]][m[nx][ny]] = 1;
            }
          }
        } 
      }
    }
  }
  //cout << G[1][2];
  int str,gl;
  str = m[a][b];
  gl = m[c][dd];
  //cout << str << " " << gl << endl;
  int res = -1;
  //vector<vector<int>>dp(ct+1,vector<int>(ct+1,1000000000));
  int r[ct+1] = {};
  if(str == gl){
    res = 0;
  }else{
    d.clear();
    tmp = make_pair(str,0);
    d.push_front(tmp);
    r[str] = 1;
    while(!d.empty()){
      tmp = d.back();
      d.pop_back();
      for(int i = 1;i<ct+1;i++){
        //cout << tmp.first << " "<< i << endl;
        nx = G[tmp.first][i];
        //cout << nx << endl;
        
        if(nx == 0){continue;}
        //cout << "j";
        ny = tmp.second +1;
        if(i == gl){
          
          res = ny;
          break;
        }
        if(r[i] == 0){
          d.push_front(make_pair(i,ny));
          r[i] = 1;
        }
      }
      if(res != -1){
        break;
      }
    }
  
  }
  
  
  cout << res;
  //cout << sum;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:10: error: expected ']' before '+' token
   10 |   char [h+1][w+1];
      |          ^
      |          ]
a.cc:10:8: error: structured binding declaration cannot have type 'char'
   10 |   char [h+1][w+1];
      |        ^
a.cc:10:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:10:9: error: conflicting declaration 'auto h'
   10 |   char [h+1][w+1];
      |         ^
a.cc:7:7: note: previous declaration as 'int h'
    7 |   int h,w,a,b,c,dd;
      |       ^
a.cc:10:13: error: expected initializer before '[' token
   10 |   char [h+1][w+1];
      |             ^
a.cc:16:7: error: 's' was not declared in this scope
   16 |       s[i][j] = st[j-1];
      |       ^
a.cc:30:26: error: 's' was not declared in this scope
   30 |       if(m[i][j] == 0 && s[i][j] == '.'){
      |                          ^
a.cc:60:16: error: 's' was not declared in this scope
   60 |             if(s[nx][ny] != '#' && s[i][j] != '#' && m[nx][ny] != m[i][j]){
      |                ^