#include <vector> #include <iostream> #include <algorithm> using namespace std; struct pos { int x; int y; }; vector<pos> beenAt; vector<vector<char>> maze; char emptyy = '.'; char wall = '#'; int goalx; int goaly; bool goThere(int x, int y) { if (x >= 0 && x < maze.size()) { if (y >= 0 && y < maze[x].size()) { if (maze[x][y] == emptyy) { pos theyPos; theyPos.x = x; theyPos.y = y; auto iterate = find(beenAt.begin(), beenAt.end(), theyPos); if (iterate == beenAt.end()) { return true; } } } } return false; } bool pathFind(int x, int y) { int howManyGoad = 0; if (goThere(x + 1, y)) { howManyGoad += 1; pos newPo; newPo.x = x; newPo.y = y; beenAt.push_back(newPo); return pathFind(x + 1, y); } if (goThere(x - 1, y)) { howManyGoad += 1; pos newPo; newPo.x = x; newPo.y = y; beenAt.push_back(newPo); return pathFind(x - 1, y); } if (goThere(x, y + 1)) { howManyGoad += 1; pos newPo; newPo.x = x; newPo.y = y; beenAt.push_back(newPo); return pathFind(x, y + 1); } if (goThere(x, y - 1)) { howManyGoad += 1; pos newPo; newPo.x = x; newPo.y = y; beenAt.push_back(newPo); return pathFind(x, y - 1); } if (goalx == x && goaly == y) { return true; } if (howManyGoad == 0) { return false; } } int main() { int n, m; int startx, starty; cin >> n >> m; cin >> startx >> starty; cin >> goalx >> goaly; for (int i = 0; i < n; i++) { vector<char> appendVec; for (int x = 0; x < m; x++) { char dummy; cin >> dummy; appendVec.push_back(dummy); } maze.push_back(appendVec); } cout << pathFind(startx, starty); return 0; }