#include #include #include using namespace std; int bfs(int r,int t,int n) { //ok we have NxN grid //we start from 0,0 and move current pos +-x and +-y // cout<<"doing for knight("< > q; int dist[n][n]; memset(dist,0,sizeof(int)*n*n); int visited[n][n]; memset(visited,0,sizeof(int)*n*n); //cout<(x,y)); visited[0][0]=1; while(!q.empty()) { //now set distances of x+-i and y+-i to q.front +1 pair pos = q.front(); //cout<<"q.front() is-"<=0 && newx[i]=0 && newy[j](newx[i],newy[j])); q.push(pair(newy[j],newx[i])); //set them as visited visited[newx[i]][newy[j]]=1; visited[newy[j]][newx[i]]=1; } } } q.pop(); } if(dist[n-1][n-1]==0)return -1; else return dist[n-1][n-1]; } int main() { //use bfs to find the shortest path int n; cin>>n; //now for each pair i,j will have to find out the paths for(int i=1;i