Language: C++

#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
#define ford(b,a) for(int i=b;i>=a;i--)
typedef pair<int, int> pi;
#define PI 3.14159265359
#define vi vector<int>
long long mod=1000000007;
//int count=INT_MAX;
 
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};
int n,m;
vector<vector<int>> vis;
vector<vi> p;
int isv(int x,int y){
    if(x<0||y<0||x>=n||y>=m){
        return 0;
    }
    return 1;
}
void dfs(vector<string> &a,int x,int y){
    if(!isv(x,y)) return;
    if(vis[x][y]||a[x][y]=='#') return;
    vis[x][y]=1;
    if(isv(x-1,y)&&!vis[x-1][y]) dfs(a,x-1,y);
    if(isv(x,y-1)&&!vis[x][y-1]) dfs(a,x,y-1);
    if(isv(x+1,y)&&!vis[x+1][y]) dfs(a,x+1,y);
    if(isv(x,y+1)&&!vis[x][y+1]) dfs(a,x,y+1);
    return;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testcases=1;
    //cin>>testcases;
    //cout<<t;
    //scanf("%d",&t);
    //int t=testcases;
    while(testcases--){
        //int n,m;
        cin>>n>>m;
        int x1,y1,x2,y2;
        cin>>x1>>y1;
        cin>>x2>>y2;
        x1--;
        y1--;
        x2--;
        y2--;
        vector<string> a(n);
        fori(0,n){
            cin>>a[i];
        }
        if(a[x2][y2]=='#'){
            cout<<"-1";
        }
        vis=vector<vi>(n,vi(m,0));
        dfs(a,x2,y2);
        if(vis[x1][y1]){
            cout<<0<<endl;
            continue;
        }
        p=vector<vi> (n,vi(m,-1));
        queue<pi> q;
        fori(0,n){
            forj(0,m){
                if(!vis[i][j]) continue;
                p[i][j]=0;
                q.push({i,j});
                // for(int x=i-2;x<=i+2;x++){
                //     for(int y=j-2;y<=j+2;y++){
                //         if(!isv(x,y)) continue;
                //         p[x][y]=1;
                //     }
                // }
            }
        }
        while(!q.empty()){
            pi ddd=q.front();
            q.pop();
            int i=ddd.first;
            int j=ddd.second;
            for(int x=i-2;x<=i+2;x++){
                for(int y=j-2;y<=j+2;y++){
                    if(!isv(x,y)) continue;
                    if(a[x][y]=='#') continue;
                    if(p[x][y]==-1){
                        p[x][y]=p[i][j]+1;
                        q.push({x,y});
                    }
                    else if(p[x][y]>p[i][j]+1){
                        p[x][y]=p[i][j]+1;
                    }
                }
            }
        }
        vis=vector<vi>(n,vi(m,0));
        dfs(a,x1,y1);
        int ans=INT_MAX;
        int t=0;
        fori(0,n){
            forj(0,m){
                if(!vis[i][j]) continue;
                if(p[i][j]==-1) continue;
                //t=1;
                ans=min(ans,p[i][j]);
            }
        }
        if(ans==INT_MAX|){
            cout<<"-1"<<endl;
            continue;
        }
        cout<<ans<<endl;
    }               

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:121:25: error: expected primary-expression before ')' token
  121 |         if(ans==INT_MAX|){
      |                         ^