Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    int h,w;
    cin >> h >> w;
    unsigned long long ans = 0;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    char s[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> s[i][j];
        }
    }

    if(abs(dh - ch) <= 2 && abs(dw - cw) <= 2){
        cout << 1 << endl;
        return 0;
    }

    cout << ans << endl;

    return 0;
}




#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <limits.h>
#include <stdio.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// Solving a maze using bfs
#define WALL '#'
#define PATH '.'
class coord{
    public:
    coord(){}
    coord(int _x,int _y):x(_x),y(_y){}
    int x,y;
};

class maze{
    public:
        maze(int _h,int _w):h(_h),w(_w){
            m = vector<vector<char>>(h,vector<char>(w));
            d = vector<vector<int>>(h,vector<int>(w,-1));
        }
        void input_map(){
            rep(i,h){
                string si; cin >> si;
                rep(j,w){
                    m[i][j] = si[j];
                    if(si[j]==WALL) wall_n++;
                    if(si[j]==PATH) path_n++;
                }
            }
        }
        void set_start(coord _s){ s = _s; }
        void calc_distance(){
            queue<coord> q;
            q.push(s);
            d[s.x][s.y]=0;
            while(q.size()){
                coord u = q.front(); q.pop();
                rep(ix,3)rep(jx,3){
                    if(abs(ix-1)+abs(jx-1)==2) continue;                    
                    int i = ix-1 + u.x;
                    int j = jx-1 + u.y;
                    
                    int gotoright = true;
                    int gotodown  = true;
                    if(ix-1 == -1) gotoright = false;
                    if(jx-1 == -1) gotodown  = false;
                    
                    if(i>=0&&i<h&&j>=0&&j<w&&d[i][j]==-1&&m[i][j]==PATH){
                        d[i][j] = d[u.x][u.y]+1;
                        q.push(coord(i,j));
                    }
                    /*
                    else if(i>=0&&i<h&&j>=0&&j<w&&d[i][j]==-1&&m[i][j]==WALL){
                        if(ix-1 == -1){
                            if(i-2>=0 && d[i-2][j]==-1&& m[i-2][j]==PATH){
                                d[i-2][j] = d[u.x][u.y]+1;
                                q.push(coord(i-2,j));
                            }else if(i-1>=0 && d[i-1][j]==-1&& m[i-1][j]==PATH){
                                d[i-1][j] = d[u.x][u.y]+1;
                                q.push(coord(i-1,j));
                            }
                        }else if(ix-1 == 1){
                           if(i+2<h && d[i+2][j]==-1&& m[i+2][j]==PATH){
                                d[i+2][j] = d[u.x][u.y]+1;
                                q.push(coord(i+2,j));
                            }else if(i+1>=0 && d[i+1][j]==-1&& m[i+1][j]==PATH){
                                d[i+1][j] = d[u.x][u.y]+1;
                                q.push(coord(i+1,j));
                            }
                        }
                        if(jx-1 == -1){
                            if(j-2>=0 && d[i][j-2]==-1&& m[i][j-2]==PATH){
                                d[i][j-2] = d[u.x][u.y]+1;
                                q.push(coord(i,j-2));
                            }else if(j-1>=0 && d[i][j-1]==-1&& m[i][j-1]==PATH){
                                d[i][j-1] = d[u.x][u.y]+1;
                                q.push(coord(i,j-2));
                            }
                        }else if(jx-1 == 1){
                            if(j+2<w && d[i][j+2]==-1&& m[i][j+2]==PATH){
                                d[i][j+2] = d[u.x][u.y]+1;
                                q.push(coord(i,j+2));
                            }else if(j+1<w && d[i][j+1]==-1&& m[i][j+1]==PATH){
                                d[i][j+1] = d[u.x][u.y]+1;
                                q.push(coord(i,j+1));
                            }
                        }
                    }
                    */
                }
            }               
        }
        int distance(coord g){return d[g.x][g.y];}
        int number_of_wall(){return wall_n;}
        int number_of_path(){return path_n;}
        void print_map(){
            rep(i,h){
                rep(j,w) cout << m[i][j];
                cout << endl;
            }
        }       
        void print_distance(){
            rep(i,h){
                rep(j,w) cout << d[i][j] << " ";
                cout << endl;
            }
        }
    private:
        int h,w;
        vector<vector<char>> m;
        vector<vector<int>> d;
        vector<vector<int>> magic;
        coord s;
        int wall_n = 0;
        int path_n = 0;
};

int main()
{
    int h,w;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    
    maze mz(h, w);
    mz.input_map();
    coord cs(ch-1, cw-1);
    //coord cs(0, 0);
    mz.set_start(cs);
    mz.calc_distance();
    
    coord ce(dh-1, dw-1);
    //coord ce(0, 3);
    int ans = mz.distance(ce);
    mz.print_distance();
    mz.print_map();
    cout << ans << endl;

    return 0;
}



Compiler output:
a.cc:167:5: error: redefinition of 'int main()'
  167 | int main()
      |     ^~~~
a.cc:14:5: note: 'int main()' previously defined here
   14 | int main()
      |     ^~~~