Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
static const long long INF = 1000000;
using p = pair<int64_t,int64_t>;

//引数として２つのpをとって移動の可否、更には魔法の有無を調べる
int cost(p p1, p p2,vector<vector<char>> & road){
    if (p1 == p2){
        return -100;
    }
    else if (road[p1.first][p1.second] == '#' or road[p2.first][p2.second] == '#'){
        return -100;
    }
    else if (p1.first == p2.first and abs(p1.second - p2.second) < 2){
        return 0;
    }
    else if (p1.second == p2.second and abs(p1.first - p2.first) < 2){
        return 0;
    }
    else if (abs(p1.first - p2.first) < 3 and abs(p1.second - p2.second) < 3){
        return 1;
    }
    else{
        return -100;
    }
}

//ダイクストラのアルゴリズム
int dijkstra(int h,int w,int xs,int ys,int xg, int yg,vector<vector<char>> & road){
    int64_t min = INF;
    vector <vector<int>> color (h,vector<int> (w,0));
    vector <vector<int64_t>> d (h,vector<int64_t> (w,INF));
    d[xs][ys] = 0;
    //優先度を決める関数をラムダ式で記述する
    bool c = [](p cc, p ccc,vector<vector<int64_t>> & d){
        if (d[cc.first][cc.second] < d[ccc.first][ccc.second]){
            return false;
        }
        else if(d[cc.first][cc.second] > d[ccc.first][ccc.second]){
            return true;
        }
        else if (cc.first > ccc.first){
            return true;
        }
        else if (cc.first < ccc.first){
            return false;
        }
        else if (cc.second > ccc.second){
            return true;
        }
        else {
            return false;
        }
        return false;
    }
    //優先度付きキューで高速化してみる

    priority_queue <p,vector<p>,decltype(c)> pq(c);
    rep(i,h){
        rep(j,w){
            p pe = {i,j};
            pq.push(pe);
        }
    }

    rep(a,w * h){
        min = INF;
        p u = {INF,INF};
    //キューが空欄でない限りdが一番小さい座標を取り出してその隣接点の情報を更新する
        if(!pq.empty()){
            u = pq.top();
            pq.pop();
            rep(i,h){    
                rep(j,w){
                    p pp = {i,j};
                    if (cost(u,pp,road) != -100 and d[pp.first][pp.second] > d[u.first][u.second] + cost(u,pp,road)){
                        d[pp.first][pp.second] = d[u.first][u.second] + cost(u,pp,road);
                    }
                }
            }
        }
    //キューが空欄ならループを終えてゴールの値を返す
        else if(d[xg][yg] == INF){
            return -1;
        }
        else {
            return d[xg][yg];
        }
        
    }
    return 0;
}


int main(){
    int h,w,xs,ys,xg,yg;
    cin >> h >> w >> xs >> ys >> xg >> yg;
    vector<vector<char>> road (h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> road[i][j];
        }
    }
    int k = dijkstra(h,w,xs-1,ys-1,xg-1,yg-1,road);
    cout << k << endl;
    
}

Compiler output:
a.cc: In function 'int dijkstra(int, int, int, int, int, int, std::vector<std::vector<char> >&)':
a.cc:59:5: error: expected ',' or ';' before 'priority_queue'
   59 |     priority_queue <p,vector<p>,decltype(c)> pq(c);
      |     ^~~~~~~~~~~~~~
a.cc:63:13: error: 'pq' was not declared in this scope; did you mean 'pe'?
   63 |             pq.push(pe);
      |             ^~
      |             pe
a.cc:71:13: error: 'pq' was not declared in this scope; did you mean 'p'?
   71 |         if(!pq.empty()){
      |             ^~
      |             p