Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

#define int long long

const int mxN = 1e3+1;

int h, w, ch, cw, dh, dw, col[mxN][mxN], d[mxN*mxN];
char g[mxN][mxN];

set<int> adj[mxN*mxN];

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

void dfs(int i, int j, int c) {
    col[i][j] = c;
    for (int k = 0; k < 4; k++) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (ni < 0 || ni >= h) continue;
        if (nj < 0 || nj >= w) continue;
        if (col[ni][nj] || g[i][j] == '#') continue;

        dfs(ni, nj, c);
    }
}

int bfs() {
    for (int i = 1; i < mxN*mxN; i++) d[i] = INF;
    queue<int> q;
    q.push(col[ch][cw]);
    d[col[ch][cw]] = 0;

    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto v : adj[u]) {
            if (d[u]+1 < d[v]) {
                d[v] = d[u]+1;
                q.push(v);
            }
        }
    }

    if (d[col[dh][dw]] == INF) return -1;
    return d[col[dh][dw]];
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--; cw--; dh--; dw--;
    for (int i = 0; i < h; i++) {
        string tmp; cin >> tmp;
        for (int j = 0; j < w; j++) g[i][j] = tmp[j];
    }

    int cind = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (col[i][j] || g[i][j] == '#') continue;
            dfs(i, j, cind);
            cind++;
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (col[i][j] == 0) continue;
            for (int x = max(0, i-2); x <= min(h-1, i+2); x++) {
                for (int y = max(0, j-2); y <= min(w-1, j+2); y++) {
                    if (col[x][y] == 0) continue;
                    adj[col[i][j]].insert(col[x][y]);
                    adj[col[x][y]].insert(col[i][j]);
                }
            }
        }
    }

    cout << bfs() << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:29: error: no matching function for call to 'max(int, long long int)'
   74 |             for (int x = max(0, i-2); x <= min(h-1, i+2); x++) {
      |                          ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:74:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   74 |             for (int x = max(0, i-2); x <= min(h-1, i+2); x++) {
      |                          ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:74:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   74 |             for (int x = max(0, i-2); x <= min(h-1, i+2); x++) {
      |                          ~~~^~~~~~~~
a.cc:75:33: error: no matching function for call to 'max(int, long long int)'
   75 |                 for (int y = max(0, j-2); y <= min(w-1, j+2); y++) {
      |                              ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:75:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   75 |                 for (int y = max(0, j-2); y <= min(w-1, j+2); y++) {
      |                              ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:75:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   75 |                 for (int y = max(0, j-2); y <= min(w-1, j+2); y++) {
      |                              ~~~^~~~~~~~