Language: C++

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int _main(){
    
    int h,w;
    cin >> h >> w;  
    int _sx,_sy,sx,sy;
    cin >> _sy >> _sx;  
    int _gx,_gy,gx,gy;
    cin >> _gy >> _gx;
    sx = _sx-1; sy = _sy-1;
    gx = _gx-1; gy = _gy-1;

    vector<vector<bool>> road(w, vector<bool>(h));
    for (int y=0; y<h; y++) {
        for (int x=0; x<w; x++) {
            char c;
            cin >> c;
            if(c=='.'){
                road[x][y]=true;
            }else{
                road[x][y]=false;
            }
        }
    }

    vector<vector<int>> cost(w, vector<int>(h,INFINITY));
    queue<tuple<int,int>> searchfrom;
    vector<vector<bool>> searching_b(w, vector<bool>(h,false));
    searchfrom.push(tuple<int,int>(sx,sy));
    int costnow = 0;
    while(true){
        queue<tuple<int,int>> searching = queue<tuple<int,int>>(searchfrom);
        searching_b = vector<bool>(w, vector<bool>(h,false));
        queue<tuple<int,int>> searched  = queue<tuple<int,int>>();
        searchfrom = queue<tuple<int,int>>();
        while(searching.size()>0){
            tuple<int,int> coord = searching.front();
            int cx = get<0>(coord); int cy = get<1>(coord);
            searching.pop();


            if(cx==gx && cy==gy){
                return costnow;
            }

            for(int x=max(0,cx-1); x<=min(w-1,cx+1); x++){
                for(int y=max(0,cy-1); y<=min(h-1,cy+1); y++){
                    int lenSu = abs(x-cx)+abs(y-cy);
                    if(road[x][y] && costnow<cost[x][y]){
                        if(lenSu==0){
                            cost[x][y] = costnow;
                            searched.push(tuple<int,int>(x,y));
                        }else if(lenSu==1 && !searching_b[x][y]){
                            searching_b[x][y]=true;
                            searching.push(tuple<int,int>(x,y));
                        }
                    }
                }
            }
        }
        while(searched.size()>0){
            tuple<int,int> coord = searched.front();
            int cx = get<0>(coord); int cy = get<1>(coord);
            searched.pop();

            for(int x=max(0,get<0>(coord)-2); x<=min(w-1,get<0>(coord)+2); x++){
                for(int y=max(0,get<1>(coord)-2); y<=min(h-1,get<1>(coord)+2); y++){
                    if(road[x][y] && costnow<cost[x][y]){
                        searchfrom.push(tuple<int,int>(x,y));
                    }
                }
            }
        }
        if(searchfrom.size()==0) return -1;
        costnow++;
    }
}

int main(){
    int result = _main();
    cout << result;
    return 0;
}

Compiler output:
a.cc: In function 'int _main()':
a.cc:29:47: warning: overflow in conversion from 'float' to 'std::vector<int>::value_type' {aka 'int'} changes value from '+Inff' to '2147483647' [-Woverflow]
   29 |     vector<vector<int>> cost(w, vector<int>(h,INFINITY));
      |                                               ^~~~~~~~
a.cc:36:60: error: no matching function for call to 'std::vector<bool>::vector(int&, std::vector<bool>)'
   36 |         searching_b = vector<bool>(w, vector<bool>(h,false));
      |                                                            ^
In file included from /usr/include/c++/14/vector:67,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_bvector.h:870:9: note: candidate: 'template<class _InputIterator, class> std::vector<bool, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Alloc = std::allocator<bool>]'
  870 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:870:9: note:   template argument deduction/substitution failed:
a.cc:36:60: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<bool>')
   36 |         searching_b = vector<bool>(w, vector<bool>(h,false));
      |                                                            ^
/usr/include/c++/14/bits/stl_bvector.h:857:7: note: candidate: 'std::vector<bool, _Alloc>::vector(std::initializer_list<bool>, const allocator_type&) [with _Alloc = std::allocator<bool>; allocator_type = std::allocator<bool>]'
  857 |       vector(initializer_list<bool> __l,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:857:37: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<bool>'
  857 |       vector(initializer_list<bool> __l,
      |              ~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:849:7: note: candidate: 'std::vector<bool, _Alloc>::vector(const std::vector<bool, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Alloc = std::allocator<bool>; std::__type_identity_t<_Alloc> = std::allocator<bool>]'
  849 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:849:28: note:   no known conversion for argument 1 from 'int' to 'const std::vector<bool>&'
  849 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |              ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:842:7: note: candidate: 'std::vector<bool, _Alloc>::vector(std::vector<bool, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Alloc = std::allocator<bool>; std::__type_identity_t<_Alloc> = std::allocator<bool>]'
  842 |       vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:842:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<bool>&&'
  842 |       vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
      |              ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:827:7: note: candidate: 'std::vector<bool, _Alloc>::vector(std::vector<bool, _Alloc>&&, const allocator_type&, std::false_type) [with _Alloc = std::allocator<bool>; allocator_type = std::allocator<bool>; std::false_type = std::false_type]'
  827 |       vector(vector&& __x, const allocator_type& __a, false_type)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:827:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_bvector.h:822:7: note: candidate: 'std::vector<bool, _Alloc>::vector(std::vector<bool, _Alloc>&&, const allocator_type&, std::true_type) [with _Alloc = std::allocator<bool>; allocator_type = std::allocator<bool>; std::true_type = std::true_type]'
  822 |       vector(vector&& __x, const allocator_type& __a, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:822:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_bvector.h:818:7: note: candidate: 'std::vector<bool, _Alloc>::vector(std::vector<bool, _Alloc>&&) [with _Alloc = std::allocator<bool>]'
  818 |       vector(vector&&) = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:818:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_bvector.h:809:7: note: candidate: 'std::vector<bool, _Alloc>::vector(const std::vector<bool, _Alloc>&) [with _Alloc = std::allocator<bool>]'
  809 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:809:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_bvector.h:795:7: note: candidate: 'std::vector<bool, _Alloc>::vector(size_type, const bool&, const allocator_type&) [with _Alloc = std::allocator<bool>; size_type = long unsigned int; allocator_type = std::allocator<bool>]'
  795 |       vector(size_type __n, const bool& __value,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:795:41: note:   no known conversion for argument 2 from 'std::vector<bool>' to 'const bool&'
  795 |       vector(size_type __n, const bool& __value,
      |                             ~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:790:7: note: candidate: 'std::vector<bool, _Alloc>::vector(size_type, const allocator_type&) [with _Alloc = std::allocator<bool>; size_type = long unsigned int; allocator_type = std::allocator<bool>]'
  790 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:790:51: note:   no known conversion for argument 2 from 'std::vector<bool>' to 'const std::vector<bool>::allocator_type&' {aka 'const std::allocator<bool>&'}
  790 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |                             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:784:7: note: candidate: 'std::vector<bool, _Alloc>::vector(const allocator_type&) [with _Alloc = std::allocator<bool>; allocator_type = std::allocator<bool>]'
  784 |       vector(const allocator_type& __a)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:784:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_bvector.h:777:7: note: candidate: 'std::vector<bool, _Alloc>::vector() [with _Alloc = std::allocator<bool>]'
  777 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_bvector.h:777:7: note:   candidate expects 0 arguments, 2 provided