#include #include using namespace std; int main() { int guardCount; int incidentCount; cin >> guardCount >> incidentCount; int * guardX = new int[guardCount]; int * guardY = new int[guardCount]; int incidentX =0; int incidentY =0; for (int i = 0; i> guardX[i] >> guardY[i]; } for (int j = 0; j,int>> fronta; cin >> incidentX; cin >> incidentY; fronta.push_back(make_pair(make_pair(incidentX,incidentY),0)); bool found = false; pair,int> processCoord; int ** visited = new int*[5001]; for (int z = 0;z<5001;z++) { visited[z] = new int[5001]; for (int m=0;m<5001;m++) { visited[z][m] = 0; } } while (!found){ processCoord = fronta.front(); fronta.pop_front(); if (visited[processCoord.first.first][processCoord.first.second]) continue; visited[processCoord.first.first][processCoord.first.second] = 1; if (guardX[processCoord.first.first] && guardY[processCoord.first.second]){ cout << processCoord.second << endl; found = true; continue; } for(int k = -1;k<=1;k++) { for(int l = -1;l<=1;l++) { pair novyCoord = make_pair(processCoord.first.first+k,processCoord.first.second+l); if (novyCoord.first > 5000 || novyCoord.first<0 || novyCoord.second>5000 || novyCoord.second<0){ continue; } //cout << processCoord.second << endl; fronta.push_back(make_pair(novyCoord,processCoord.second+1)); } } } } }