http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2566
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 char map[120][120]; 4 int v[120][120];//用来标记某点所能到达的所有路径 5 int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}}; 6 int n,m; 7 void dfs(int x,int y,int t) 8 { 9 v[x][y] = t; 10 for (int i = 0; i < 4; i ++) 11 { 12 int dx = x + dir[i][0]; 13 int dy = y + dir[i][1]; 14 if (dx >= 0 && dx < n && dy >= 0 && dy < m && map[dx][dy]=='.'&&v[dx][dy]==-1) 15 { 16 dfs(dx,dy,t); 17 } 18 } 19 } 20 int main() 21 { 22 int cnt; 23 while(~scanf("%d%d%d",&n,&m,&cnt)) 24 { 25 int t = 0; 26 memset(v,-1,sizeof(v)); 27 for (int i = 0; i < n; i ++) 28 scanf("%s",map[i]); 29 for (int i = 0; i < n; i ++) 30 { 31 for (int j = 0; j < m; j ++) 32 { 33 if (map[i][j]=='.' && v[i][j]==-1) 34 { 35 dfs(i,j,t++); 36 } 37 } 38 } 39 int x1,y1,x2,y2; 40 while(cnt--) 41 { 42 scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 43 if (v[x1][y1]==-1||v[x2][y2]==-1||v[x1][y1]!=v[x2][y2])//若没被标记过或标记的D和J不是同一个数则不能相遇 44 printf("No "); 45 else 46 { 47 if ((x2-x1+y2-y1)%2==0) 48 printf("Yes "); 49 else 50 printf("No "); 51 } 52 } 53 } 54 return 0; 55 }