// C++ Code implementation for above problem #include #define LL long long using namespace std; LL N,M; int parent[205][205]; class QItem { public: int row; int col; int dist; QItem(int x, int y, int w) : row(x), col(y), dist(w) { } }; int minDistance(int x1,int y1,int x2,int y2) { QItem source(0, 0, 0); bool visited[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { visited[i][j] = false; } } source.row = x1; source.col = y1; // applying BFS on matrix cells starting from source queue q; q.push(source); visited[source.row][source.col] = true; while (!q.empty()) { QItem p = q.front(); q.pop(); if (p.row==x2 && p.col == y2) { return p.dist; } // UL if (p.row - 2 >= 0 && p.col-1>=0 && visited[p.row - 2][p.col-1] == false) { q.push(QItem(p.row - 2, p.col-1, p.dist + 1)); visited[p.row - 2][p.col-1] = true; parent[p.row - 2][p.col-1]=0; } // UR if (p.row - 2 >= 0 && p.col+1=0 && visited[p.row + 2][p.col-1] == false) { q.push(QItem(p.row + 2, p.col-1, p.dist + 1)); visited[p.row + 2][p.col-1] = true; parent[p.row + 2][p.col-1]=4; } // L if (p.col - 2 >=0 && visited[p.row][p.col - 2] == false) { q.push(QItem(p.row, p.col - 2, p.dist + 1)); visited[p.row][p.col - 2] = true; parent[p.row][p.col - 2]=5; } } return -1; } int main() { LL n,x1,y1,x2,y2,x,y; cin>>n; cin>>x1>>y1>>x2>>y2; N=n,M=n; int ret=minDistance(x1,y1,x2,y2); if(ret==-1) { cout<<"Impossible"< s; while(1) { if(x==x1&&y==y1) break; dir=parent[x][y]; //cout<