NAKANJ-SPOJ


Can anyone help in finding mistake in my c++ solution for this problem:

#include <bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)	
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define N 1000005
using namespace std;
// vector<ll> edges[N];
// bool f[N][N]={0};
// bool visi[N][N]={0};

ll dx[]={0,-1,-1,1,1,-2,-2,2,2};
ll dy[]={0,2,-2,2,-2,-1,1,-1,1};
bool bfs(ll a1, ll b1, ll a2, ll b2){
    ll f[9][9], visi[9][9];
    memset(f,0,sizeof(f));
    memset(visi,0,sizeof(visi));
    queue<pair<ll,ll> > q;
    q.push(mp(a1,b1));
    visi[a1][b1]=0;
    while(!q.empty()){
        a1=q.front().ff;
        b1=q.front().ss;
        q.pop();
        if(a1==a2 && b1==b2){
            return f[a2][b2];
        }
        ll m,n;
        for(ll i=1;i<=8;i++){
            m=a1+dx[i];
            n=b1+dy[i];
            if(m>8||m<1||n>8||n<1)
            continue;
            else{
            q.push(mp(m,n));
            visi[m][n]=1;
            f[m][n]=f[a1][b1]+1;
            }
        }
    }
}

int main(){
    crap;
    ll t,b1,b2;
    char a1,a2;
    cin>>t;
    while(t--){
        cin>>a1>>b1>>a2>>b2;
        cout<<bfs(a1-'a'+1,b1,a2-'a'+1,b2)<<endl;
    }
    return 0;
    
}

Problem is in the return type.Return type is bool and you are returning int.Just make it int and also there is no use of visi[][] array.

damn, such a silly mistake :joy::joy:

Yeah…:rofl::rofl::rofl::rofl: