#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define ff first #define ss second #define mpa make_pair using namespace std; typedef long long LL; int dxtemp[8]; int dytemp[8]; bool valid(int x, int y, int N, int M) { if(x <= 0 || y <= 0 || x > N || y > M) return false; return true; } int bfs(pair p1, pair p2, pair p3) { int N = p3.ff; int M = p3.ss; queue, int> > Que; map, bool> Vis; Que.push(mpa(p1, 0)); while(!Que.empty()) { pair, int> temp = Que.front(); Que.pop(); if(temp.ff.ff == p2.ff && temp.ff.ss == p2.ss) return temp.ss; int x = temp.ff.ff; int y = temp.ff.ss; int dis = temp.ss + 1; if(Vis.count(mpa(x, y))) continue; Vis[mpa(x, y)] = true; for(int i = 0; i <= 7; ++i) { int x1 = x + dxtemp[i]; int y1 = y + dytemp[i]; if(valid(x1, y1, N, M)) Que.push(mpa(mpa(x1, y1), dis)); } } return -1; } void printarray (int arg[], int length) { for (int n=0; n p1; p1.ff = x1; p1.ss = y1; pair p2; p2.ff = x2; p2.ss = y2; pair p3; p3.ff = N; p3.ss = M; int ans = bfs(p1, p2, p3); return ans; } int main(){ int n; cin >> n; for(int i1=1;i1