#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <math.h>
#include <queue>
using namespace std;
/*
T2 HDU 1175
*/
struct place
{
int x;
int y;
};
int n,m;
int b[1002][1002];
int vis[1002][1002];
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int turn;
void bfs(int x1,int y1,int x2,int y2)
{
place a,t;
queue<place> que;
a.x=x1;a.y=y1;
que.push(a);
turn =0;
vis[x1][y1] = 1;
while(!que.empty())
{
a=que.front();
que.pop();
if(a.x == x2 && a.y == y2)
{
cout<<"YES"<<endl;
return ;
}
}
cout<<"NO"<<endl;
}
int main()
{
int i,j;
int x1,x2,y1,y2;
int q;
while(cin>>n>>m)
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
cin>>b[i][j];
cin>>q;
for(i=0;i<q;i++)
{
cin>>x1>>y1>>x2>>y2;
if(b[x1][y1] != b[x2][y2] || !b[x1][y2] ||(x1==x2 && y1==y2))
{
cout<<"NO\n"<<endl;
}
memset(vis,0,sizeof(vis));
bfs(x1,y1,x2,y2);
}
}
return 0;
}
图论 BFS HDU 1175
最新推荐文章于 2020-09-13 18:56:17 发布