#include #include #include using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; int map[178][178]; int n,nrfa,cx,cy,kx,ky; struct elem { signed short x; signed short y; signed short d; }; void read_data() { int fx,fy; ifstream in; in.open("alee.in"); in >> n; in >> nrfa; for(int i=1;i<=nrfa;i++) { in >> fx; in >> fy; map[fx][fy]=-1; }; in >> kx; in >> ky; in >> cx; in >> cy; in.close(); }; void initMap() { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if (map[i][j]==0) map[i][j]=-2; }; }; map[kx][ky]=0; } void generateLeeNumbers() { //Put the first element into the queue queue sor; elem e; e.x=kx; e.y=ky; e.d=0; sor.push(e); elem test=sor.front(); //Let's do the lee while((!sor.empty())&&(map[cx][cy]==-2)) { elem x=sor.front(); sor.pop(); for(int k=0;k<=3;k++) { elem y; y.x=x.x+dx[k]; y.y=x.y+dy[k]; if((y.x<=n)&&(y.y<=n)) { if(map[y.x][y.y]==-2) { y.d=x.d+1; map[y.x][y.y]=y.d; sor.push(y); }; }; }; }; }; void writeResult() { ofstream out; out.open("alee.out"); out << map[cx][cy]+1; out.close(); }; int main() { read_data(); initMap(); generateLeeNumbers(); writeResult(); return 0; }