Language: C++

// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < static_cast<ll>(n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= static_cast<ll>(n); ++i)
#define RRANGE(i, m, n) for(ll i = static_cast<ll>(m); i >= static_cast<ll>(n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

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

struct visit {
    ll x_;
    ll y_;
    ll count_;
};

auto comp = [] (visit const& a, visit const& b) {
    return a.count_ > b.count_;
};

int run(istream& in, ostream& out) {
    ll H, W, Ch, Cw, Dh, Dw;
    in >> H >> W;
    in >> Ch >> Cw;
    in >> Dh >> Dw;
    Ch--;
    Cw--;
    Dh--;
    Dw--;
    vector<string> S{};
    S.resize(H);
    REP(i, H) {
        in >> S[i];
    }
    vector<vector<ll>> d(H, vector<ll>(W, INF));
    ll ans = -1;

    priority_queue<visit, std::vector<visit>, decltype(comp)> q{comp};
    q.emplace(visit{Cw, Ch, 0});
    while(!q.empty()) {
        auto v = q.top(); q.pop();
        auto x = v.x_;
        auto y = v.y_;
        auto count = v.count_;
        if (d[y][x] != INF) {
            continue;
        }
        d[v.y_][v.x_] = v.count_;
        if (y == Dh && x == Dw) {
            ans = count;
            break;
        }
        REP(i, 4) {
            auto xx = x + dx[i];
            auto yy = y + dy[i];
            if (xx >=0 && yy >=0 && xx < W && yy < H && S[yy][xx] == '.') {
                q.emplace(visit{xx, yy, count});
            }
        }
        RANGE(xxx, -2, 2) {
            RANGE(yyy, -2, 2) {
                if (xxx == 0 && yyy == 0) continue;
                auto xxxx = x + xxx;
                auto yyyy = y + yyy;
                if (xxxx >=0 && yyyy >=0 && xxxx < W && yyyy < H && S[yyyy][xxxx] == '.') {
                    q.emplace(visit{xxxx, yyyy, count+1});
                }
            }
        }
    }
    out << fixed << setprecision(10);
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Compiler output:
a.cc:54:17: error: reference to 'visit' is ambiguous
   54 | auto comp = [] (visit const& a, visit const& b) {
      |                 ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:3:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:8: note:                 'struct visit'
   48 | struct visit {
      |        ^~~~~
a.cc:54:17: error: 'visit' has not been declared
   54 | auto comp = [] (visit const& a, visit const& b) {
      |                 ^~~~~
a.cc:54:33: error: reference to 'visit' is ambiguous
   54 | auto comp = [] (visit const& a, visit const& b) {
      |                                 ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:8: note:                 'struct visit'
   48 | struct visit {
      |        ^~~~~
a.cc:54:33: error: 'visit' has not been declared
   54 | auto comp = [] (visit const& a, visit const& b) {
      |                                 ^~~~~
a.cc: In lambda function:
a.cc:55:14: error: request for member 'count_' in 'a', which is of non-class type 'const int'
   55 |     return a.count_ > b.count_;
      |              ^~~~~~
a.cc:55:25: error: request for member 'count_' in 'b', which is of non-class type 'const int'
   55 |     return a.count_ > b.count_;
      |                         ^~~~~~
a.cc: In function 'int run(std::istream&, std::ostream&)':
a.cc:75:44: error: template argument 1 is invalid
   75 |     priority_queue<visit, std::vector<visit>, decltype(comp)> q{comp};
      |                                            ^
a.cc:75:44: error: template argument 2 is invalid
a.cc:75:61: error: template argument 1 is invalid
   75 |     priority_queue<visit, std::vector<visit>, decltype(comp)> q{comp};
      |                                                             ^
a.cc:75:61: error: template argument 2 is invalid
a.cc:75:65: error: cannot convert '<lambda(const int&, const int&)>' to 'int' in initialization
   75 |     priority_queue<visit, std::vector<visit>, decltype(comp)> q{comp};
      |                                                                 ^~~~
      |                                                                 |
      |                                                                 <lambda(const int&, const int&)>
a.cc:76:7: error: request for member 'emplace' in 'q', which is of non-class type 'int'
   76 |     q.emplace(visit{Cw, Ch, 0});
      |       ^~~~~~~
a.cc:76:15: error: reference to 'visit' is ambiguous
   76 |     q.emplace(visit{Cw, Ch, 0});
      |               ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:8: note:                 'struct visit'
   48 | struct visit {
      |        ^~~~~
a.cc:77:14: error: request for member 'empty' in 'q', which is of non-class type 'int'
   77 |     while(!q.empty()) {
      |              ^~~~~
a.cc:78:20: error: request for member 'top' in 'q', which is of non-class type 'int'
   78 |         auto v = q.top(); q.pop();
      |                    ^~~
a.cc:78:29: error: request for member 'pop' in 'q', which is of non-class type 'int'
   78 |         auto v = q.top(); q.pop();
      |                             ^~~
a.cc:94:19: error: request for member 'emplace' in 'q', which is of non-class type 'int'
   94 |                 q.emplace(visit{xx, yy, count});
      |                   ^~~~~~~
a.cc:94:27: error: reference to 'visit' is ambiguous
   94 |                 q.emplace(visit{xx, yy, count});
      |                           ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:8: note:                 'struct visit'
   48 | struct visit {
      |        ^~~~~
a.cc:103:23: error: request for member 'emplace' in 'q', which is of non-class type 'int'
  103 |                     q.emplace(visit{xxxx, yyyy, count+1});
      |                       ^~~~~~~
a.cc:103:31: error: reference to 'visit' is ambiguous
  103 |                     q.emplace(visit{xxxx, yyyy, count+1});
      |                               ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:8: note:                 'struct visit'
   48 | struct visit {
      |        ^~~~~