use std::collections::VecDeque; const DX: [isize; 8] = [-1, 1, 0, 0, -2, 2, 0, 0]; const DY: [isize; 8] = [0, 0, -1, 1, 0, 0, -2, 2]; fn main() { let mut hw = String::new(); std::io::stdin().read_line(&mut hw).ok(); let hw: Vec = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let h = hw[0]; let w = hw[1]; let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let sx = temp[0]-1; let sy = temp[1]-1; let gx = temp[2]-1; let gy = temp[3]-1; let grid = (0..h).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); temp.trim().chars().map(|c| c as isize - '0' as isize).collect::>() }) .collect::>(); let mut deque = VecDeque::new(); deque.push_back((sx, sy)); let mut checked = vec![vec![false; w]; h]; checked[sx][sy] = true; while let Some((x, y)) = deque.pop_front() { for dir in 0..8 { let nx = x as isize + DX[dir]; let ny = y as isize + DY[dir]; if nx >= 0 && ny >= 0 && nx < h as isize && ny < w as isize { let nx = nx as usize; let ny = ny as usize; if checked[nx][ny] { continue; } if dir < 4 && (grid[x][y] - grid[nx][ny]).abs() > 1 { continue; } if dir >= 4 && grid[x][y] != grid[nx][ny] { continue; } checked[nx][ny] = true; deque.push_back((nx, ny)); } } } if checked[gx][gy] { println!("YES"); } else { println!("NO"); } }