fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. vector <string> grid;
  5. bool visited[500+9][500+9];
  6. int row,col;
  7.  
  8. int sx,sy;
  9. int fx,fy;
  10.  
  11.  
  12. bool condition(int i,int j){
  13. if(i<0 || j<0 || i>=row || j>=col)
  14. return false;
  15. return true;
  16. }
  17. char c='.';
  18. void DFS(int i,int j){
  19. visited[i][j]=true;
  20.  
  21. if(grid[i][j-1]==c && condition(i,j-1))
  22. DFS(i,j-1);
  23. if(grid[i-1][j]==c && condition(i-1,j))
  24. DFS(i-1,j);
  25. if(grid[i+1][j]==c && condition(i+1,j))
  26. DFS(i+1,j);
  27. if(grid[i][j+1]==c && condition(i,j+1))
  28. DFS(i,j+1);
  29.  
  30. }
  31.  
  32. int main(){ //freopen("in.txt","r",stdin);
  33. cin>>row>>col;
  34. string s;
  35. for(int i=0;i<row;i++){
  36. cin>>s;
  37. grid.push_back(s);
  38. }
  39.  
  40. cin>>sx>>sy;
  41. cin>>fx>>fy;
  42. DFS(sx-1,sy-1);
  43. if(visited[fx-1][fy-1]) cout<<"YES"<<endl;
  44. else cout<<"NO"<<endl;
  45. }
  46.  
Runtime error #stdin #stdout 0s 3528KB
stdin
4 6
X...XX
...XX.
.X..X.
......
1 6
2 2
stdout
Standard output is empty