#K7421. Taco Maze
Taco Maze
Taco Maze
You are given a grid of size \(m \times n\) where each cell is marked as either 'H' (habitable) or 'I' (inhabitable). The task is to determine whether there exists a path from the top-left corner (cell (1,1)) to the bottom-right corner (cell (m,n)) moving only in the four cardinal directions (up, down, left, right) and only through habitable cells ('H').
Note that if either the starting cell or the destination cell is inhospitable ('I'), the answer is automatically "NO". Use Breadth-First Search (BFS) or any other suitable graph traversal method to solve the problem.
Input constraints: \(1 \leq m,n \leq 1000\) (for example).
inputFormat
The first line contains two integers m and n separated by a space. The next m lines each contain a string of n characters, where each character is either 'H' or 'I'.
outputFormat
Output a single line containing "YES" if there exists a path from the top-left to the bottom-right cell according to the rules described, otherwise output "NO".## sample
3 3
HHH
HIH
HHH
YES