#include using namespace std; // N x N matrix int N, xstart, ystart, xdest, ydest; int matrix[200][200]; struct Node { int x, y; vector> path; bool const operator==(const Node& ob) const { return x == ob.x && y == ob.y; } bool operator<(const Node& ob) const { return x < ob.x || (x == ob.x && y < ob.y); } }; int row[] = { -2, -2, 0, 2, 2, 0 }; int col[] = { -1, 1, 2, 1, -1, -2 }; bool isValid(int x, int y) { return (x >= 0 && x < N) && (y >= 0 && y < N); } void printPath(vector> path) { cout << "Destination Found:\t"; for (pair p: path) cout << "(" << p.first << ", " << p.second << ") "; cout << endl; } int findPath( int x, int y) { vector> path; path.push_back({x, y}); queue Q; Node src = {x, y, path}; Q.push(src); map visited; visited[src] = true; while (!Q.empty()) { Node curr = Q.front(); Q.pop(); int i = curr.x, j = curr.y; path = curr.path; if (i == xdest && j == ydest) { cout << path.size() - 1 << "\n"; //printPath(path); vector < string > s; for(int i = 1; i py) s.push_back("UR"); else if(x == px && y > py) s.push_back("R"); else if(x > px && y > py) s.push_back("LR"); else if(x > px && y < py) s.push_back("LL"); else if(x == px && y < py) s.push_back("L"); } for(int i = 0; i < s.size(); i++) cout << s[i] << " "; return path.size() - 1; } int n = matrix[i][j]; for (int k = 0; k < 6; k++) { int x = i + row[k] * n; int y = j + col[k] * n; if (isValid(x, y)) { path.push_back({x, y}); Node next = {x, y, path}; if (!visited.count(next)) { Q.push(next); visited[next] = true; } path.pop_back(); } } } return INT_MAX; } int main() { cin >> N; for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) matrix[i][j] = 1; cin >> xstart >> ystart >> xdest >> ydest; int len = findPath(xstart, ystart); if (len != INT_MAX) ; else cout << "Impossible"; return 0; }