Language: C++

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int h, w;

vector<int> dijkstra(map<int, vector<pair<int, int>>> &g, int start)
{
    ll n = h * w;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pque;
    pque.push({0, start});
    vector<int> ret(n + 2, IINF);
    while (!pque.empty())
    {
        auto cost = pque.top().first;
        auto cur = pque.top().second;
        pque.pop();
        if (ret[cur] <= cost)
            continue;
        ret[cur] = cost;
        for (auto &&x : g[cur])
        {
            int next = x.first;
            ll d = x.second;
            if (cost + d < ret[next])
                pque.push({cost + d, next});
        }
    }

    return ret;
}

bool is_valid(int y, int x)
{
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main()
{
    cin >> h >> w;
    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--;
    sx--;
    gy--;
    gx--;
    vector<string> g(h);
    rep(i, h)
    {
        cin >> g[i];
    }
    map<int, vector<pair<int, int>>> graph;
    rep(y, h)
    {
        rep(x, w)
        {
            int dx[5] = {-2, -1, 0, 1, 2};
            int dy[5] = {-2, -1, 0, 1, 2};
            rep(i, 5) rep(j, 5)
            {
                if (dy[i] == 0 && dx[j] == 0)
                    continue;
                int ny = y + dy[i];
                int nx = x + dx[j];

                if (is_valid(ny, nx) && g[ny][nx] == '.')
                {
                    if ((dy[i] == 1 && dx[j] == 0) || (dy[i] == -1 && dx[j] == 0) || (dy[i] == 0 && dx[j] == 1) || (dy[i] == 0 && dx[j] == -1))
                    {
                        graph[w * y + x].push_back({w * ny + nx, 0});
                    }
                    else
                    {
                        graph[w * y + x].push_back({w * ny + nx, 1});
                    }
                }
            }
        }
    }

    ll n = h * w;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pque;
    pque.push({0, start});
    vector<int> ret(n + 2, IINF);
    while (!pque.empty())
    {
        auto cost = pque.top().first;
        auto cur = pque.top().second;
        pque.pop();
        if (ret[cur] <= cost)
            continue;
        ret[cur] = cost;
        for (auto &&x : g[cur])
        {
            int next = x.first;
            ll d = x.second;
            if (cost + d < ret[next])
                pque.push({cost + d, next});
        }
    }

    auto cost = ret;
    if (cost[w * gy + gx] == IINF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << cost[w * gy + gx] << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:100:19: error: 'start' was not declared in this scope
  100 |     pque.push({0, start});
      |                   ^~~~~
a.cc:100:14: error: no matching function for call to 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::push(<brace-enclosed initializer list>)'
  100 |     pque.push({0, start});
      |     ~~~~~~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >; value_type = std::pair<int, int>]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::value_type&' {aka 'const std::pair<int, int>&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::vector<std::pair<int, int> >; _Compare = std::greater<std::pair<int, int> >; value_type = std::pair<int, int>]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::value_type&&' {aka 'std::pair<int, int>&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:112:26: error: request for member 'first' in 'x', which is of non-class type 'char'
  112 |             int next = x.first;
      |                          ^~~~~
a.cc:113:22: error: request for member 'second' in 'x', which is of non-class type 'char'
  113 |             ll d = x.second;
      |                      ^~~~~~