Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool check(vector<string> &m, ll x, ll y)
{
	return (m.size() > x && x >= 0 && y >= 0 && m[0].size() > y && m[x][y] == '.');
}

ll dfs(vector<string> &m, vector<vector<ll>> &dp, ll x, ll y, ll fx, ll fy)
{
	// cout << "(x, y) " << x << " " << y << endl;
	if(x == fx && y == fy)
	{
		// cout << "return" << endl;
		return 0;
	}

	if(dp[x][y] != -1)
		return dp[x][y];

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

	dp[x][y] = INT_MAX;

	ll w = INT_MAX;
	for(ll i = 0; i < 4; i++)
	{
		ll nx = x + dx[i];
		ll ny = y + dy[i];
		if(check(m, nx, ny) && dp[nx][ny] != INT_MAX)
		{	
			w = min(w, dfs(m, dp, nx, ny, fx, fy));
		}
	}

	ll dx2[] = {-2, -1, 0, 1, 2};
	ll dy2[] = {-2, -1, 0, 1, 2};
	// cout << "For " << x << " " << y << endl;
	for(ll i = 0; i < 5; i++)
	{
		ll nx = x + dx2[i];
		for(ll i2 = 0; i2 < 5; i2++)
		{
			ll ny = y + dy2[i2];
			if(check(m, nx, ny) && dp[nx][ny] != INT_MAX)
			{
				// cout << m[nx][ny] << " " << nx << " " << ny << endl;
				w = min(w, 1 + dfs(m, dp, nx, ny, fx, fy));
			}
		}
	}

	dp[x][y] = min(INT_MAX, w);
	// cout << "____________\n(x, y) " << x << " " << y << " dp " << dp[x][y] << endl;
	return dp[x][y];
}

int main()
{
	ll h, w;
	cin >> h >> w;

	ll ch, cw;
	cin >> ch >> cw;

	ll dh, dw;
	cin >> dh >> dw;

	vector<string> m(h);
	vector<vector<ll>> dp(h, vector<ll>(w, -1));
	for(ll i = 0; i < h; i++)
		cin >> m[i];

	// cout << "dh " << dh - 1 << " dw " << dw - 1 << endl;
	ll u = dfs(m, dp, ch - 1, cw - 1, dh - 1, dw - 1);
	u = (u >= INT_MAX) ? -1 : u;
	cout << u << endl;
}


Compiler output:
a.cc: In function 'll dfs(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::vector<long long int> >&, ll, ll, ll, ll)':
a.cc:57:23: error: no matching function for call to 'min(int, ll&)'
   57 |         dp[x][y] = min(INT_MAX, w);
      |                    ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:57:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   57 |         dp[x][y] = min(INT_MAX, w);
      |                    ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:57:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   57 |         dp[x][y] = min(INT_MAX, w);
      |                    ~~~^~~~~~~~~~~~