Language: C++

// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 100005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll b) { if (a % b == 0)	return (a / b);	return (a / b + 1);}
inline ll binlen(ll n) {
	ll c = 0;
	while (n > 0)
		++c , n /= 2;
	return c;
}
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

ll n, m, sx, sy, fx, fy;
vector<vector<char>> grid;
vvl dist;
vl dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
bool isvalid(ll x, ll y)
{
	if (x < 1 || x > n || y < 1 || y > m)
		return false;
	if (grid[x][y] == '#')
		return false;
	return true;
}
void bfs()
{
	queue<pair<ll, ppl>, vector<pair<ll, ppl>>, greater<pair<ll, ppl>>> q;
	dist[sx][sy] = 0;
	q.push({0, {sx, sy}});
	while (!q.empty())
	{
		ll x = q.top().ss.ff, y = q.top().ss.ss, d = q.top().ff;
		q.pop();
		loop(i, 4)
		{
			if (isvalid(x + dx[i], y + dy[i]))
			{
				if (d < dist[x + dx[i]][y + dy[i]])
				{
					dist[x + dx[i]][y + dy[i]] = d;
					q.push({d, {x + dx[i], y + dy[i]}});
				}
			}
		}
		FOR(i, -2, 2)
		{
			FOR(j, -2, 2)
			{
				if (isvalid(x + i, y + j))
				{
					if (d + 1 < dist[x + i][y + j])
					{
						dist[x + i][y + j] = min(dist[x+i][y+j],d + 1);
						q.push({dist[x+i][y+j] + 1, {x + i, y + j}});
					}
				}
			}
		}
	}
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	cin >> n >> m >> sx >> sy >> fx >> fy;
	grid = vector<vector<char>>(n + 1, vector<char>(m + 1));
	dist = vvl(n + 1, vl(m + 1, inf));
	FOR(i, 1, n)	FOR(j, 1, m)	cin >> grid[i][j];
	bfs();
	if (dist[fx][fy] == inf)
		cout << -1 << END;
	else
		cout << dist[fx][fy] << END;



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}


Compiler output:
a.cc: In function 'void bfs()':
a.cc:93:75: error: wrong number of template arguments (3, should be at least 1)
   93 |         queue<pair<ll, ppl>, vector<pair<ll, ppl>>, greater<pair<ll, ppl>>> q;
      |                                                                           ^
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:13:
/usr/include/c++/14/bits/stl_queue.h:96:11: note: provided for 'template<class _Tp, class _Sequence> class std::queue'
   96 |     class queue
      |           ^~~~~
a.cc:95:11: error: request for member 'push' in 'q', which is of non-class type 'int'
   95 |         q.push({0, {sx, sy}});
      |           ^~~~
a.cc:96:19: error: request for member 'empty' in 'q', which is of non-class type 'int'
   96 |         while (!q.empty())
      |                   ^~~~~
a.cc:98:26: error: request for member 'top' in 'q', which is of non-class type 'int'
   98 |                 ll x = q.top().ss.ff, y = q.top().ss.ss, d = q.top().ff;
      |                          ^~~
a.cc:99:19: error: request for member 'pop' in 'q', which is of non-class type 'int'
   99 |                 q.pop();
      |                   ^~~
a.cc:102:48: error: 'y' was not declared in this scope
  102 |                         if (isvalid(x + dx[i], y + dy[i]))
      |                                                ^
a.cc:104:37: error: 'd' was not declared in this scope
  104 |                                 if (d < dist[x + dx[i]][y + dy[i]])
      |                                     ^
a.cc:107:43: error: request for member 'push' in 'q', which is of non-class type 'int'
  107 |                                         q.push({d, {x + dx[i], y + dy[i]}});
      |                                           ^~~~
a.cc:115:52: error: 'y' was not declared in this scope
  115 |                                 if (isvalid(x + i, y + j))
      |                                                    ^
a.cc:117:45: error: 'd' was not declared in this scope
  117 |                                         if (d + 1 < dist[x + i][y + j])
      |                                             ^
a.cc:120:51: error: request for member 'push' in 'q', which is of non-class type 'int'
  120 |                                                 q.push({dist[x+i][y+j] + 1, {x + i, y + j}});
      |                                                   ^~~~