Language: C++

#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;

string masu[1010];
int h, w, ch, cw, dh, dw;
long ans = -1;

struct st {
	int hh;
	int ww;
	int wnum;
	st(int a, int b, int c) {
		hh = a;
		ww = b;
		wnum = c;
	}
};

queue<st> solve;
int warpnum = -1;
int warpcount;

void move(int hh, int ww, int wnum) {
	if (hh <= 0 || ww <= 0 || hh > h || ww > w) {
		return;
	}
	if (masu[hh][ww] != '.') {
		return;
	}
	masu[hh][ww] = wnum + '0';
	solve.push(st(hh, ww, wnum));
	move(hh - 1, ww, wnum);
	move(hh + 1, ww, wnum);
	move(hh, ww - 1, wnum);
	move(hh, ww + 1, wnum);
	if (hh == dh && ww == dw) {
		if (ans != -1) {
			ans = min(ans, wnum);
		}
		else {
			ans = wnum;
		}
		return;
	}
	return;
}

void warp(int hh, int ww, int wnum) {
	int i, j;
	if (hh <= 0 || ww <= 0 || hh > h || ww > w) {
		return;
	}
	if (wnum==warpnum) {
		for (i = hh - 2; i <= hh + 2; i++) {
			for (j = ww - 2; j <= ww + 2; j++) {
				warp(i, j, wnum + 1);
			}
		}
	}
	else if (wnum == warpnum + 1) {
		if (masu[hh][ww] == '.') {
			masu[hh][ww] = wnum + '0';
			solve.push(st(hh, ww, wnum));
			warpcount++;
			if (hh == dh && ww == dw) {
				if (ans != -1) {
					ans = min(ans, wnum);
				}
				else {
					ans = wnum;
				}
				return;
			}
		}
	}
	return;
}

void printmasu() {
	int i, j;
	cout << endl;
	cout << "warpcount = " << warpcount << endl;
	for (i = 1; i <= h; i++) {
		for (j = 1; j <= w; j++) {
			cout << masu[i][j];
		}
		cout << endl;
	}
	cout << endl;
}

void initflg() {
	int i, j;
	for (i = 1; i <=h ; i++) {
		for (j = 1; j <= w; j++) {
			if (masu[i][j] - '0' == warpnum+1) {
				masu[i][j] = '.';
			}
		}
	}
}

int main()
{
	int i, j, k;

	cin >> h >> w;
	cin >> ch >> cw;
	cin >> dh >> dw;
	for (i = 1; i <= h; i++) {
		cin >> masu[i];
		masu[i] = '#' + masu[i];
	}

	move(ch, cw, 0);
	if (ans != -1) {
		cout << ans << endl;
		return 0;
	}

	st tmp(0, 0, 0);
	while (1) {
		warpnum++;
		warpcount = 0;
		while (!solve.empty()) {
			tmp = solve.front();
			if (tmp.wnum != warpnum)break;
			solve.pop();
			warp(tmp.hh, tmp.ww ,tmp.wnum);
		}
		//printmasu();
		initflg();
		if (solve.empty())break;

		while (warpcount>0) {
			tmp = solve.front();
			solve.pop();
			move(tmp.hh, tmp.ww, tmp.wnum);
			warpcount--;
		}
		//printmasu();

		if (ans != -1)break;
	}

	cout << ans << endl;

	return 0;
}


Compiler output:
a.cc: In function 'void move(int, int, int)':
a.cc:41:34: error: no matching function for call to 'min(long int&, int&)'
   41 |                         ans = min(ans, wnum);
      |                               ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:41:34: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   41 |                         ans = min(ans, wnum);
      |                               ~~~^~~~~~~~~~~
/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,
                 from a.cc:4:
/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:41:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   41 |                         ans = min(ans, wnum);
      |                               ~~~^~~~~~~~~~~
a.cc: In function 'void warp(int, int, int)':
a.cc:70:50: error: no matching function for call to 'min(long int&, int&)'
   70 |                                         ans = min(ans, wnum);
      |                                               ~~~^~~~~~~~~~~
/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:70:50: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   70 |                                         ans = min(ans, wnum);
      |                                               ~~~^~~~~~~~~~~
/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
/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:70:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   70 |                                         ans = min(ans, wnum);
      |                                               ~~~^~~~~~~~~~~