Language: C++

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1005
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi 3.14159265358979323846
#define Q ll _; cin >> _; while(_--)
#define endl "\n"
#define flush fflush(stdout);

int vis[MAX][MAX];
ll a[MAX][MAX];
ll n,m;
ll gp;
ll i1,j1,i2,j2;
ll st,en;
int mat[MAX][MAX];
vector<ll> ad[MAX];

void dfs(ll i, ll j){
    vis[i][j] = 1;
    a[i][j] = gp;
    if((i==i1)&&(j==j1)){
        st = gp;
    }
    if((i==i2)&&(j==j2)){
        en = gp;
    }

    if((i>1)&&(!vis[i-1][j])&&(a[i-1][j])){
        dfs(i-1,j);
    }
    if((i<n)&&(!vis[i+1][j])&&(a[i+1][j])){
        dfs(i+1,j);
    }
    if((j>1)&&(!vis[i][j-1])&&(a[i][j-1])){
        dfs(i,j-1);
    }
    if((j<m)&&(!vis[i][j+1])&&(a[i][j+1])){
        dfs(i,j+1);
    }
}

void dfs1(ll i, ll j){
    ll i1 = max((ll)1,i-2);
    ll i2 = min(n,i+2);
    ll j1 = max((ll)1,j-2);
    ll j2 = min(m,j+2);
    for(ll ii=i1;ii<=i2;ii++){
        for(ll jj=j1;jj<=j2;jj++){
            if(a[ii][jj]){
                ll a1 = a[i][j];
                ll a2 = a[ii][jj];
                if((!mat[a1][a2])&&(a1!=a2)){
                    ad[a1].push_back(a2);
                    ad[a2].push_back(a1);
                }
                mat[a1][a2]=1;
                mat[a2][a1]=1;
            }
        }
    }
}
int vis1[MAX];
int bfs(ll s, ll e){
    queue<pair<ll,ll> > q;
    q.push(make_pair(s,0));
    while(!q.empty()){
        pair<ll,ll> pr = q.front();
        q.pop();
        ll x = pr.first;
        ll dist = pr.second;
        vis1[x] = 1;
        if(x==en){
            return dist;
        }
        for(ll i=0;i<ad[x].size();i++){
            ll x1 = ad[x][i];
            if(!vis1[x1]){
                q.push(make_pair(x1,dist+1));
            }
        }
    }
    return -1;
}

int main(){

    fast;

    ll i,j;
    cin >> n >> m;
    cin >> i1 >> j1 >> i2 >> j2;

    char b[n+1][m+1];

    for(i=0;i<n;i++){
        string a1;
        cin >> a1;
        for(j=0;j<m;j++){
            if(a1[j]=='.'){
                a[i+1][j+1] = -1;
            }
            else{
                a[i+1][j+1] = 0;
            }
        }
    }
    gp = 0;
    st = 0;
    en = 0;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if((!vis[i][j])&&(a[i][j])){
                gp++;
                dfs(i,j);
            }
        }
    }

    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(a[i][j]){
                dfs1(i,j);
            }
        }
    }
/*
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }

    for(i=1;i<=gp;i++){
        cout << i << " : ";
        for(j=0;j<ad[i].size();j++){
            ll x = ad[i][j];
            cout << x << " ";
        }
        cout << endl;
    }
    cout << "start : " << st << endl;
    cout << "end : " << en << endl;
*/
    cout << bfs(st,en) << endl;
}

//    cout << fixed << setprecision(12);


Compiler output:
a.cc:20:7: error: 'long long int j1' redeclared as different kind of entity
   20 | ll i1,j1,i2,j2;
      |       ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:254:1: note: previous declaration 'double j1(double)'
  254 | __MATHCALL (j1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'void dfs(long long int, long long int)':
a.cc:28:19: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   28 |     if((i==i1)&&(j==j1)){
      |                  ~^~~~
a.cc: In function 'int main()':
a.cc:98:15: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and 'double(double) noexcept')
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |     ~~~~~~~~~ ^~ ~~
      |         |        |
      |         |        double(double) noexcept
      |         std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/iostream:42:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double (*)(double) noexcept'
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'short int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(short int)j1' to 'short int&'
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'short unsigned int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(short unsigned int)j1' to 'short unsigned int&'
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(int)j1' to 'int&'
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'unsigned int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(unsigned int)j1' to 'unsigned int&'
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(long int)j1' to 'long int&'
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long unsigned int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(long unsigned int)j1' to 'long unsigned int&'
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long long int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(long long int)j1' to 'long long int&'
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long long unsigned int' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(long long unsigned int)j1' to 'long long unsigned int&'
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  328 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/14/istream:328:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'void*' [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:98:18: error: cannot bind rvalue '(void*)j1' to 'void*&'
/usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:122:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'} [-fpermissive]
   98 |     cin >> i1 >> j1 >> i2 >> j2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
/usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]' (near match)
  126 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:126:7: note:   conversion of argument 1 would be ill-formed:
a.cc:98:18: error: invalid conversion from 'double (*)(double) noexcept' to 'std::basic_istream<char>::__ios_type& (*)(std::basic_is