Getting partial correct for BFS


#1

Getting partial correct for BFS approach using sets! How can I optimize it? Is there any error?
( Using set of string as for pair<int,int>, needed to hash the points explicitly)

` unordered_set ump;

struct kknight{
int x;
int y;
int level;
};
int Solution::knight(int A, int B, int C, int D, int E, int F) {
ump.clear();
if(C==E && D==F) return 0;
int X[]={ -2,-1,1,2,2,1,-1,-2};
int Y[]={ -1,2,2,1,-1,-2,-2,1};
struct kknight src = {C,D,0};
// struct knight dest={E,F,-1};

queue<struct kknight> q;
q.push(src);
int ans=INT_MAX;
string p=to_string(C)+" "+to_string(D);
ump.insert(p);

while(!q.empty()){
    struct kknight temp=q.front();
    q.pop();
    for(int i=0;i<8;++i){
        int curx=temp.x+X[i];
        int cury=temp.y+Y[i];
        p=to_string(curx)+" "+to_string(cury);
        
        
            if(curx==E && cury==F) {
            ans=min(ans,temp.level+1);
           // cout<<"Dest at"<<ans<<" ";
            }
            else
            if(ump.find(p) == ump.end()){
                
            if( curx>0 && cury>0 && curx<=A && cury<=B){
               // cout<<curx<<cury<<" ";
            struct kknight pp={curx,cury, temp.level+1};
            q.push(pp);
            ump.insert(p);
        }
    
    }
}

}
if(ans==INT_MAX) ans=-1;
return ans;
}
`