Liens Sujet: Cliquez ici
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 110;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0 , 0, -1, 1};
char g[N][N];
bool st[N][N];
int n, ax, ay, bx, by;
bool dfs(int x, int y)
{
if(g[x][y] == '#') return false;
if(x == bx && y == by) return true;
st[x][y] = true;
for(int i = 0; i < 4; ++i)
{
int a = x + dx[i], b = y + dy[i];
if(a < 0 || a >= n || b < 0 || b >= n) continue;
if(st[a][b]) continue;
if(dfs(a, b)) return true;
}
return false;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
memset(st, false, sizeof st);
scanf("%d", &n);
for(int i = 0; i < n; ++i) scanf("%s", g[i]);
scanf("%d%d%d%d", &ax, &ay, &bx, &by);
if(dfs(ax, ay)) puts("YES");
else puts("NO");
}
return 0;
}