Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;

#define int long long

const int CN = 1e3 + 3;
const int INF = 1e9;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

int read(){
    int s = 0,ne = 1; char c = getchar();
    while(c < '0' || c > '9') ne = c == '-' ? -1 : 1, c = getchar();
    while(c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - '0', c = getchar();
    return s * ne;
}

class fs {public: int to,nxt,w; void init(int t,int n,int d) {to = t, nxt = n, w = d;} } E[CN * CN * 10];
int hd[CN * CN], ecnt = 0; void add(int x,int y,int z) {E[++ecnt].init(y, hd[x], z); hd[x] = ecnt;}

int n, m, col[CN][CN], idx = 0, A, B, C, D; bool can[CN][CN]; queue<int> x, y;

class DJ {public: int v, id; bool operator < (const DJ &a) const {return v > a.v;}} ;
DJ mk(int a, int b) {DJ c; c.v = a, c.id = b; return c;}
bool vis[CN * CN]; int d[CN * CN]; priority_queue<DJ> Q;
void SP(int s){
    memset(d, 0x3f, sizeof(d)), Q.push( mk(d[s] = 0, 1) );
    while(!Q.empty()){
        int u = Q.top().id; Q.pop(); if(vis[u]) continue; vis[u] = true;
        for(int k = hd[u]; k; k = E[k].nxt){
            int v = E[k].to; if(vis[v]) continue;
            if(d[v] > d[u] + E[k].w) d[v] = d[u] + E[k].w, Q.push( mk(d[v], v) );
        }
    }
}

class DSU {
  public: int fa[CN * CN]; DSU() {for(int i = 0; i <= 1000000; i++) fa[i] = i;}
    int fd(int x) {return fa[x] ^ x ? fa[x] = fd(fa[x]) : x;}
} S;

signed main()
{
    // freopen("_in.in", "r", stdin);
    n = read(), m = read(), A = read(), B = read(), C = read(), D = read();
    for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++){
        char c; cin >> c; can[i][j] = c == '#' ? 0 : 1;
    } 
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            if(col[i][j] || !can[i][j]) continue; idx++;
            x.push(i), y.push(j);
            while(!x.empty()){
                int a = x.front(), b = y.front(); x.pop(), y.pop();
                col[a][b] = idx;
                for(int k = 0; k < 4; k++){
                    int vx = a + dx[k], vy = b + dy[k];
                    if(!vx || !vy || vx > n || vy > m) continue;
                    if(col[vx][vy] || !can[vx][vy]) continue;
                    x.push(vx), y.push(vy);
                }
            }
        }
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= m; j++)
    for(int k = max(1, i - 3); k <= min(n, i + 3); k++)
    for(int p = max(1, j - 3); p <= min(m, j + 3); p++){
        int u = col[i][j], v = col[k][p]; u = S.fd(u), v = S.fd(v); if(u == v) continue; S.fa[u] = v;           
        add(col[k][p], col[i][j], 1), add(col[i][j], col[k][p], 1);
    }
    SP(col[A][B]), printf("%lld", d[col[C][D]] < INF ? d[col[C][D]] : -1);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:72:20: error: no matching function for call to 'max(int, long long int)'
   72 |     for(int k = max(1, i - 3); k <= min(n, i + 3); k++)
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:72:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   72 |     for(int k = max(1, i - 3); k <= min(n, i + 3); k++)
      |                 ~~~^~~~~~~~~~
/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,
                 from a.cc:5:
/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:72:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   72 |     for(int k = max(1, i - 3); k <= min(n, i + 3); k++)
      |                 ~~~^~~~~~~~~~
a.cc:73:20: error: no matching function for call to 'max(int, long long int)'
   73 |     for(int p = max(1, j - 3); p <= min(m, j + 3); p++){
      |                 ~~~^~~~~~~~~~
/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:73:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   73 |     for(int p = max(1, j - 3); p <= min(m, j + 3); p++){
      |                 ~~~^~~~~~~~~~
/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:73:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   73 |     for(int p = max(1, j - 3); p <= min(m, j + 3); p++){
      |                 ~~~^~~~~~~~~~