//code written by a living bruh moment
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;

public class Rating2000_540C {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int m = in.nextInt();
        char[][] grid = new char[n][m];
        char[][] grid2 = new char[n][m];
        for(int i = 0; i<n; i++){
            String s = in.next();
            for(int j = 0; j<m; j++){
                grid[i][j] = s.charAt(j);
                grid2[i][j] = s.charAt(j);
            }
        }
        int startn = in.nextInt()-1;
        int startm = in.nextInt()-1;
        int endn = in.nextInt()-1;
        int endm = in.nextInt()-1;
        boolean cracked = false;
        if(grid[endn][endm] == 'X') cracked = true;
        boolean path = false;
        boolean doit = true;
        Queue<Integer> x = new LinkedList<Integer>();
        Queue<Integer> y = new LinkedList<Integer>();
        x.add(startn);
        y.add(startm);
        //bfs
        boolean check = Math.abs(startn-endn) + Math.abs(startm-endm) == 1 ? true: false;
        while(!x.isEmpty() && !y.isEmpty()){
            startn = x.poll();
            startm = y.poll();
            if(startn==endn && startm==endm){
                path = true;
                break;
            }
            if(startn<0 || startm<0 || startn>=grid.length || startm>=grid[0].length){

            }
            else if(grid[startn][startm] == 'X' && !doit){
            }
            else{
                doit=false;
                grid[startn][startm] = 'X';
                x.add(startn+1);
                x.add(startn-1);
                x.add(startn);
                x.add(startn);
                y.add(startm);
                y.add(startm);
                y.add(startm+1);
                y.add(startm-1);
            }
        }
        if(path){
            int count = 0;
            int l = endn + 1;
            int r = endm;
            if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

            }
            else if(grid2[l][r] == '.'){
                ++count;
            }
            l = endn - 1;
            r = endm;
            if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

            }
            else if(grid2[l][r] == '.'){
                ++count;
            }
            l = endn;
            r = endm + 1;
            if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

            }
            else if(grid2[l][r] == '.'){
                ++count;
            }
            l = endn;
            r = endm - 1;
            if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

            }
            else if(grid2[l][r] == '.'){
                ++count;
            }
            if(check){
                if(grid2[endn][endm] == '.'){
                    out.print(count>=1?"YES":"NO");
                }
                else{
                    out.print("YES");
                }
            }
            else if(cracked){
                if(count>=1){
                    out.print("YES");
                }
                else{
                    out.print("NO");
                }
            }
            else{
                if(count>=2){
                    out.print("YES");
                }
                else{
                    out.print("NO");
                }
            }
        }
        else{
            out.print("NO");
        }
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong()
        {
            return Long.parseLong(next());
        }
        public double nextDouble()
        {
            return Double.parseDouble(next());
        }
        public String nextLine()
        {
            try
            {
                return reader.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }
        public boolean hasNext()
        {
            String next=null;
            try
            {
                next=reader.readLine();
            }
            catch(Exception e)
            {
            }
            if(next==null)
            {
                return false;
            }
            tokenizer=new StringTokenizer(next);
            return true;
        }
    }
}


//code written by a living bruh moment
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;

public class Rating2000_540C {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int m = in.nextInt();
        char[][] grid = new char[n][m];
        char[][] grid2 = new char[n][m];
        for(int i = 0; i<n; i++){
            String s = in.next();
            for(int j = 0; j<m; j++){
                grid[i][j] = s.charAt(j);
                grid2[i][j] = s.charAt(j);
            }
        }
        int startn = in.nextInt()-1;
        int startm = in.nextInt()-1;
        int endn = in.nextInt()-1;
        int endm = in.nextInt()-1;
        boolean cracked = false;
        if(grid[endn][endm] == 'X') cracked = true;
        boolean path = false;
        boolean doit = true;
        Queue<Integer> x = new LinkedList<Integer>();
        Queue<Integer> y = new LinkedList<Integer>();
        x.add(startn);
        y.add(startm);
        //bfs
        while(!x.isEmpty() && !y.isEmpty()){
            startn = x.poll();
            startm = y.poll();
            if(startn==endn && startm==endm){
                path = true;
                break;
            }
            if(startn<0 || startm<0 || startn>=grid.length || startm>=grid[0].length){

            }
            else if(grid[startn][startm] == 'X' && !doit){
            }
            else{
                doit=false;
                grid[startn][startm] = 'X';
                x.add(startn+1);
                x.add(startn-1);
                x.add(startn);
                x.add(startn);
                y.add(startm);
                y.add(startm);
                y.add(startm+1);
                y.add(startm-1);
            }
        }
        if(path){
            if(cracked){
                out.print("YES");
            }
            else{
                int count = 0;
                int l = endn + 1;
                int r = endm;
                if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

                }
                else if(grid2[l][r] == '.'){
                    ++count;
                }
                l = endn - 1;
                r = endm;
                if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

                }
                else if(grid2[l][r] == '.'){
                    ++count;
                }
                l = endn;
                r = endm + 1;
                if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

                }
                else if(grid2[l][r] == '.'){
                    ++count;
                }
                l = endn;
                r = endm - 1;
                if(l<0 || r<0 || l>=grid.length || r>=grid[0].length){

                }
                else if(grid2[l][r] == '.'){
                    ++count;
                }
                if(count>=2){
                    out.print("YES");
                }
                else{
                    out.print("NO");
                }
            }
        }
        else{
            out.print("NO");
        }
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong()
        {
            return Long.parseLong(next());
        }
        public double nextDouble()
        {
            return Double.parseDouble(next());
        }
        public String nextLine()
        {
            try
            {
                return reader.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }
        public boolean hasNext()
        {
            String next=null;
            try
            {
                next=reader.readLine();
            }
            catch(Exception e)
            {
            }
            if(next==null)
            {
                return false;
            }
            tokenizer=new StringTokenizer(next);
            return true;
        }
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static final char X = 'X';
    private static final char D = '.';

    private static int n;
    private static int m;
    private static int r2;
    private static int c2;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        char[][] board = new char[n][m];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.next().toCharArray();
        }
        int r1 = scanner.nextInt() - 1;
        int c1 = scanner.nextInt() - 1;
        r2 = scanner.nextInt() - 1;
        c2 = scanner.nextInt() - 1;
        boolean possible = search(board, r1, c1);
        if (possible) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean search(char[][] board, int r1, int c1) {
        // set cell to visited
        board[r1][c1] = X;

        List<Pair> next = getNext(r1, c1);
        Collections.sort(next);
        for (Pair p : next) {
            if (p.r == r2 && p.c == c2) {
                if (board[p.r][p.c] == 'X') {
                    return true;
                }
                return checkfordot(board);
            }
            if (board[p.r][p.c] != 'X') {
                if (search(board, p.r, p.c)) {
                    return true;
                }
            }
        }

        // reset cell
        board[r1][c1] = D;
        return false;
    }

    private static boolean checkfordot(char[][] board) {
        List<Pair> pairs = getNext(r2, c2);
        for (Pair p : pairs) {
            if (board[p.r][p.c] == D) {
                return true;
            }
        }
        return false;
    }

    private static List<Pair> getNext(int r1, int c1) {
        List<Pair> pairs = new ArrayList<>();
        if (ok(r1 - 1, c1)) {
            pairs.add(new Pair(r1 - 1, c1));
        }
        if (ok(r1 + 1, c1)) {
            pairs.add(new Pair(r1 + 1, c1));
        }
        if (ok(r1, c1 - 1)) {
            pairs.add(new Pair(r1, c1 - 1));
        }
        if (ok(r1, c1 + 1)) {
            pairs.add(new Pair(r1, c1 + 1));
        }
        return pairs;
    }

    private static boolean ok(int nextR, int nextC) {
        return nextR >= 0 && nextC >= 0 && nextR < n && nextC < m;
    }

    static class Pair implements Comparable<Pair> {
        int r, c;
        Pair(int r, int c) {
            this.r = r;
            this.c = c;
        }

        @Override
        public int compareTo(Pair o) {
            return dist(this) - dist(o);
        }

        private int dist(Pair o) {
            return Math.abs(r2 - o.r) + Math.abs(c2 - o.c);
        }
    }

}


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    private static final char X = 'X';
    private static final char D = '.';

    private static int n;
    private static int m;
    private static int r2;
    private static int c2;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        char[][] board = new char[n][m];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.next().toCharArray();
        }
        int r1 = scanner.nextInt() - 1;
        int c1 = scanner.nextInt() - 1;
        r2 = scanner.nextInt() - 1;
        c2 = scanner.nextInt() - 1;
        boolean possible = search(board, r1, c1);
        if (possible) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean search(char[][] board, int r1, int c1) {
        Queue<Pair> q = new ArrayDeque<>();
        q.add(new Pair(r1, c1));

        while (!q.isEmpty()) {
            Pair p = q.poll();
            List<Pair> next = getNext(p.r, p.c);
            Collections.sort(next);
            for (Pair n : next) {
                if (n.r == r2 && n.c == c2 && board[n.r][n.c] == X) {
                    return true;
                }
                if (board[n.r][n.c] == X) {
                    continue;
                }
                q.add(n);
                board[n.r][n.c] = X;
            }
        }
        return false;
    }

    private static List<Pair> getNext(int r1, int c1) {
        List<Pair> pairs = new ArrayList<>();
        if (ok(r1 - 1, c1)) {
            pairs.add(new Pair(r1 - 1, c1));
        }
        if (ok(r1 + 1, c1)) {
            pairs.add(new Pair(r1 + 1, c1));
        }
        if (ok(r1, c1 - 1)) {
            pairs.add(new Pair(r1, c1 - 1));
        }
        if (ok(r1, c1 + 1)) {
            pairs.add(new Pair(r1, c1 + 1));
        }
        return pairs;
    }

    private static boolean ok(int nextR, int nextC) {
        return nextR >= 0 && nextC >= 0 && nextR < n && nextC < m;
    }

    static class Pair implements Comparable<Pair> {
        int r, c;
        Pair(int r, int c) {
            this.r = r;
            this.c = c;
        }

        @Override
        public int compareTo(Pair o) {
            return dist(this) - dist(o);
        }

        private int dist(Pair o) {
            return Math.abs(r2 - o.r) + Math.abs(c2 - o.c);
        }

        @Override
        public String toString() {
            return String.format("{r:%d,c:%d}", r, c);
        }
    }

}


import java.util.Scanner;

public class Main {

    private static final char X = 'X';
    private static final char D = '.';

    private static int n;
    private static int m;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        char[][] board = new char[n][m];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.next().toCharArray();
        }
        int r1 = scanner.nextInt() - 1;
        int c1 = scanner.nextInt() - 1;
        int r2 = scanner.nextInt() - 1;
        int c2 = scanner.nextInt() - 1;
        boolean possible = search(board, r1, c1, r2, c2);
        if (possible) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean search(char[][] board, int r1, int c1, int r2, int c2) {
        // set cell to visited
        board[r1][c1] = X;

        int[][] next = getNext(r1, c1);
        for (int i = 0; i < 4; i++) {
            int nextR = next[i][0];
            int nextC = next[i][1];
            if (ok(nextR, nextC)) {
                if (board[nextR][nextC] == 'X') {
                    if (nextR == r2 && nextC == c2) {
                        return true;
                    }
                } else {
                    if (search(board, nextR, nextC, r2, c2)) {
                        return true;
                    }
                }
            }
        }

        // reset cell
        board[r1][c1] = D;
        return false;
    }

    private static int[][] getNext(int r1, int c1) {
        int[][] next = new int[4][2];
        next[0][0] = r1 - 1;
        next[0][1] = c1;
        next[1][0] = r1 + 1;
        next[1][1] = c1;
        next[2][0] = r1;
        next[2][1] = c1 - 1;
        next[3][0] = r1;
        next[3][1] = c1 + 1;
        return next;
    }

    private static boolean ok(int nextR, int nextC) {
        return nextR >= 0 && nextC >= 0 && nextR < n && nextC < m;
    }

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static final char X = 'X';
    private static final char D = '.';

    private static int n;
    private static int m;
    private static int r2;
    private static int c2;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        char[][] board = new char[n][m];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.next().toCharArray();
        }
        int r1 = scanner.nextInt() - 1;
        int c1 = scanner.nextInt() - 1;
        r2 = scanner.nextInt() - 1;
        c2 = scanner.nextInt() - 1;
        boolean possible = search(board, r1, c1);
        if (possible) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean search(char[][] board, int r1, int c1) {
        // set cell to visited
        board[r1][c1] = X;

        List<Pair> next = getNext(r1, c1);
        Collections.sort(next);
        for (Pair p : next) {
            if (p.r == r2 && p.c == c2) {
                if (board[p.r][p.c] == 'X') {
                    return true;
                }
                continue;
            }
            if (board[p.r][p.c] != 'X') {
                if (search(board, p.r, p.c)) {
                    return true;
                }
            }
        }

        // reset cell
        board[r1][c1] = D;
        return false;
    }

    private static List<Pair> getNext(int r1, int c1) {
        List<Pair> pairs = new ArrayList<>();
        if (ok(r1 - 1, c1)) {
            pairs.add(new Pair(r1 - 1, c1));
        }
        if (ok(r1 + 1, c1)) {
            pairs.add(new Pair(r1 + 1, c1));
        }
        if (ok(r1, c1 - 1)) {
            pairs.add(new Pair(r1, c1 - 1));
        }
        if (ok(r1, c1 + 1)) {
            pairs.add(new Pair(r1, c1 + 1));
        }
        return pairs;
    }

    private static boolean ok(int nextR, int nextC) {
        return nextR >= 0 && nextC >= 0 && nextR < n && nextC < m;
    }

    static class Pair implements Comparable<Pair> {
        int r, c;
        Pair(int r, int c) {
            this.r = r;
            this.c = c;
        }

        @Override
        public int compareTo(Pair o) {
            return dist(this) - dist(o);
        }

        private int dist(Pair o) {
            return Math.abs(r2 - o.r) + Math.abs(c2 - o.c);
        }
    }

}


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    private static final char X = 'X';
    private static final char D = '.';

    private static int n;
    private static int m;
    private static int r2;
    private static int c2;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        char[][] board = new char[n][m];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.next().toCharArray();
        }
        int r1 = scanner.nextInt() - 1;
        int c1 = scanner.nextInt() - 1;
        r2 = scanner.nextInt() - 1;
        c2 = scanner.nextInt() - 1;
        boolean possible = search(board, r1, c1);
        if (possible) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean search(char[][] board, int r1, int c1) {
        ArrayDeque<Pair> q = new ArrayDeque<>();
        q.add(new Pair(r1, c1));

        while (!q.isEmpty()) {
            Pair p = q.pollLast();
            List<Pair> next = getNext(p.r, p.c);
            Collections.sort(next);
            for (Pair n : next) {
                if (n.r == r2 && n.c == c2 && board[n.r][n.c] == X) {
                    return true;
                }
                if (board[n.r][n.c] == X) {
                    continue;
                }
                q.addLast(n);
                board[n.r][n.c] = X;
            }
        }
        return false;
    }

    private static List<Pair> getNext(int r1, int c1) {
        List<Pair> pairs = new ArrayList<>();
        if (ok(r1 - 1, c1)) {
            pairs.add(new Pair(r1 - 1, c1));
        }
        if (ok(r1 + 1, c1)) {
            pairs.add(new Pair(r1 + 1, c1));
        }
        if (ok(r1, c1 - 1)) {
            pairs.add(new Pair(r1, c1 - 1));
        }
        if (ok(r1, c1 + 1)) {
            pairs.add(new Pair(r1, c1 + 1));
        }
        return pairs;
    }

    private static boolean ok(int nextR, int nextC) {
        return nextR >= 0 && nextC >= 0 && nextR < n && nextC < m;
    }

    static class Pair implements Comparable<Pair> {
        int r, c;
        Pair(int r, int c) {
            this.r = r;
            this.c = c;
        }

        @Override
        public int compareTo(Pair o) {
            return dist(o) - dist(this);
        }

        private int dist(Pair o) {
            return Math.abs(r2 - o.r) + Math.abs(c2 - o.c);
        }

        @Override
        public String toString() {
            return String.format("{r:%d,c:%d}", r, c);
        }
    }

}


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    private static final char X = 'X';
    private static final char D = '.';

    private static int n;
    private static int m;
    private static int r2;
    private static int c2;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        char[][] board = new char[n][m];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.next().toCharArray();
        }
        int r1 = scanner.nextInt() - 1;
        int c1 = scanner.nextInt() - 1;
        r2 = scanner.nextInt() - 1;
        c2 = scanner.nextInt() - 1;
        boolean possible = search(board, r1, c1);
        if (possible) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean search(char[][] board, int r1, int c1) {
        ArrayDeque<Pair> q = new ArrayDeque<>();
        q.add(new Pair(r1, c1));

        while (!q.isEmpty()) {
            Pair p = q.pollLast();
            List<Pair> next = getNext(p.r, p.c);
            //Collections.sort(next);
            for (Pair n : next) {
                if (n.r == r2 && n.c == c2 && board[n.r][n.c] == X) {
                    return true;
                }
                if (board[n.r][n.c] == X) {
                    continue;
                }
                q.addLast(n);
                board[n.r][n.c] = X;
            }
        }
        return false;
    }

    private static List<Pair> getNext(int r1, int c1) {
        List<Pair> pairs = new ArrayList<>();
        if (ok(r1 - 1, c1)) {
            pairs.add(new Pair(r1 - 1, c1));
        }
        if (ok(r1 + 1, c1)) {
            pairs.add(new Pair(r1 + 1, c1));
        }
        if (ok(r1, c1 - 1)) {
            pairs.add(new Pair(r1, c1 - 1));
        }
        if (ok(r1, c1 + 1)) {
            pairs.add(new Pair(r1, c1 + 1));
        }
        return pairs;
    }

    private static boolean ok(int nextR, int nextC) {
        return nextR >= 0 && nextC >= 0 && nextR < n && nextC < m;
    }

    static class Pair implements Comparable<Pair> {
        int r, c;
        Pair(int r, int c) {
            this.r = r;
            this.c = c;
        }

        @Override
        public int compareTo(Pair o) {
            return dist(o) - dist(this);
        }

        private int dist(Pair o) {
            return Math.abs(r2 - o.r) + Math.abs(c2 - o.c);
        }

        @Override
        public String toString() {
            return String.format("{r:%d,c:%d}", r, c);
        }
    }

}


import java.util.Scanner;

public class Main {

    private static final char X = 'X';
    private static final char D = '.';

    private static int n;
    private static int m;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        char[][] board = new char[n][m];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.next().toCharArray();
        }
        int r1 = scanner.nextInt() - 1;
        int c1 = scanner.nextInt() - 1;
        int r2 = scanner.nextInt() - 1;
        int c2 = scanner.nextInt() - 1;
        boolean possible = search(board, r1, c1, r2, c2);
        if (possible) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean search(char[][] board, int r1, int c1, int r2, int c2) {
        // set cell to visited
        board[r1][c1] = X;

        int[][] next = getNext(r1, c1);
        for (int i = 0; i < 4; i++) {
            int nextR = next[i][0];
            int nextC = next[i][1];
            if (ok(nextR, nextC)) {
                if (nextR == r2 && nextC == c2) {
                    if (board[nextR][nextC] == 'X') {
                        return true;
                    }
                    return checkfordot(board, r2, c2);
                }
                if (board[nextR][nextC] == 'X') {
                    if (nextR == r2 && nextC == c2) {
                        return true;
                    }
                } else {
                    if (search(board, nextR, nextC, r2, c2)) {
                        return true;
                    }
                }
            }
        }

        // reset cell
        board[r1][c1] = D;
        return false;
    }

    private static boolean checkfordot(char[][] board, int r2, int c2) {
        int[][] next = getNext(r2, c2);
        for (int i = 0; i < 4; i++) {
            int nextR = next[i][0];
            int nextC = next[i][1];
            if (ok(nextR, nextC) && board[nextR][nextC] == D) {
                return true;
            }
        }
        return false;
    }

    private static int[][] getNext(int r1, int c1) {
        int[][] next = new int[4][2];
        next[0][0] = r1 - 1;
        next[0][1] = c1;
        next[1][0] = r1 + 1;
        next[1][1] = c1;
        next[2][0] = r1;
        next[2][1] = c1 - 1;
        next[3][0] = r1;
        next[3][1] = c1 + 1;
        return next;
    }

    private static boolean ok(int nextR, int nextC) {
        return nextR >= 0 && nextC >= 0 && nextR < n && nextC < m;
    }

}


//package CF;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), m = sc.nextInt();
		g = new char[n][m];
		for (int i = 0; i < g.length; i++) {
			g[i] = sc.next().toCharArray();
		}
		int r1 = sc.nextInt() - 1, c1 = sc.nextInt() - 1;
		r2 = sc.nextInt() - 1;
		c2 = sc.nextInt() - 1;
		g[r1][c1] = '.';
		if ((r1 != r2 || c1 != c2) && g[r2][c2] != 'X' && cnt(r2, c2) < 2 || r1 == r2 && c1 == c2 && cnt(r2, c2) == 0) {
			out.println("NO");
		} else {
			g[r2][c2] = '.';
			dfs(r1, c1);
			out.println(g[r2][c2] == '!' ? "YES" : "NO");
		}
		out.flush();
		out.close();
	}

	static char[][] g;
	static int r2, c2;

	static void dfs(int i, int j) {
		g[i][j] = '!';
		if (i == r2 && j == c2)
			return;
		for (int k = 0; k < dx.length; k++) {
			int nx = i + dx[k], ny = j + dy[k];
			if (val(nx, ny)) {
				dfs(nx, ny);
			}
		}
	}

	static int[] dx = { 1, 0, -1, 0 };
	static int[] dy = { 0, -1, 0, 1 };

	static int cnt(int i, int j) {
		int res = 0;
		for (int j2 = 0; j2 < dx.length; j2++) {
			int nx = i + dx[j2], ny = j + dy[j2];
			if (val(nx, ny))
				res++;

		}
		return res;
	}

	static boolean val(int i, int j) {
		return i >= 0 && j >= 0 && i < g.length && j < g[i].length && g[i][j] == '.';
	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}


//package CF;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), m = sc.nextInt();
		g = new char[n][m];
		for (int i = 0; i < g.length; i++) {
			g[i] = sc.next().toCharArray();
		}
		int r1 = sc.nextInt()-1, c1 = sc.nextInt()-1;
		 r2 = sc.nextInt()-1; c2 = sc.nextInt()-1;
		if(!((r1 == r2 && c1 == c2) || g[r2][c2] == 'X' || cnt(r2, c2) >= 2)){
			out.println("NO");
		}
		else{
			g[r2][c2] = '.';
			dfs(r1, c1);
			out.println(g[r2][c2] == '!'?"YES":"NO");
		}
		out.flush();
		out.close();
	}

	static char[][] g;
	static int r2, c2;

	static void dfs(int i, int j) {
		g[i][j] = '!';
		if (i == r2 && j == c2)
			return;
		for (int k = 0; k < dx.length; k++) {
			int nx = i + dx[k], ny = j + dy[k];
			if (val(nx, ny))
				dfs(nx, ny);
		}
	}

	static int[] dx = { 1, 0, -1, 0 };
	static int[] dy = { 0, -1, 0, 1 };

	static int cnt(int i, int j) {
		int res = 0;
		for (int j2 = 0; j2 < dx.length; j2++) {
			int nx = i + dx[j2], ny = j + dy[j2];
			if (val(nx, ny))
				res++;

		}
		return res;
	}

	static boolean val(int i, int j) {
		return i >= 0 && j >= 0 && i < g.length && j < g[i].length && g[i][j] == '.';
	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}


//package CF;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), m = sc.nextInt();
		g = new char[n][m];
		for (int i = 0; i < g.length; i++) {
			g[i] = sc.next().toCharArray();
		}
		int r1 = sc.nextInt()-1, c1 = sc.nextInt()-1;
		 r2 = sc.nextInt()-1; c2 = sc.nextInt()-1;
		if(!(g[r2][c2] == 'X' || cnt(r2, c2) >= 2)){
			out.println("NO");
		}
		else{
			g[r2][c2] = '.';
			dfs(r1, c1);
			out.println(g[r2][c2] == '!'?"YES":"NO");
		}
		out.flush();
		out.close();
	}

	static char[][] g;
	static int r2, c2;

	static void dfs(int i, int j) {
		g[i][j] = '!';
		if (i == r2 && j == c2)
			return;
		for (int k = 0; k < dx.length; k++) {
			int nx = i + dx[k], ny = j + dy[k];
			if (val(nx, ny))
				dfs(nx, ny);
		}
	}

	static int[] dx = { 1, 0, -1, 0 };
	static int[] dy = { 0, -1, 0, 1 };

	static int cnt(int i, int j) {
		int res = 0;
		for (int j2 = 0; j2 < dx.length; j2++) {
			int nx = i + dx[j2], ny = j + dy[j2];
			if (val(nx, ny))
				res++;

		}
		return res;
	}

	static boolean val(int i, int j) {
		return i >= 0 && j >= 0 && i < g.length && j < g[i].length && g[i][j] == '.';
	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}


//package CF;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), m = sc.nextInt();
		g = new char[n][m];
		for (int i = 0; i < g.length; i++) {
			g[i] = sc.next().toCharArray();
		}
		int r1 = sc.nextInt()-1, c1 = sc.nextInt()-1;
		 r2 = sc.nextInt()-1; c2 = sc.nextInt()-1;
		if(!(((r1 != r2 || c1 != c2) && g[r2][c2] == 'X') || cnt(r2, c2) >= 2)){
			out.println("NO");
		}
		else{
			g[r2][c2] = '.';
			dfs(r1, c1);
			out.println(g[r2][c2] == '!'?"YES":"NO");
		}
		out.flush();
		out.close();
	}

	static char[][] g;
	static int r2, c2;

	static void dfs(int i, int j) {
		g[i][j] = '!';
		if (i == r2 && j == c2)
			return;
		for (int k = 0; k < dx.length; k++) {
			int nx = i + dx[k], ny = j + dy[k];
			if (val(nx, ny))
				dfs(nx, ny);
		}
	}

	static int[] dx = { 1, 0, -1, 0 };
	static int[] dy = { 0, -1, 0, 1 };

	static int cnt(int i, int j) {
		int res = 0;
		for (int j2 = 0; j2 < dx.length; j2++) {
			int nx = i + dx[j2], ny = j + dy[j2];
			if (val(nx, ny))
				res++;

		}
		return res;
	}

	static boolean val(int i, int j) {
		return i >= 0 && j >= 0 && i < g.length && j < g[i].length && g[i][j] == '.';
	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}


//package CF;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), m = sc.nextInt();
		g = new char[n][m];
		for (int i = 0; i < g.length; i++) {
			g[i] = sc.next().toCharArray();
		}
		int r1 = sc.nextInt()-1, c1 = sc.nextInt()-1;
		 r2 = sc.nextInt()-1; c2 = sc.nextInt()-1;
		if(g[r2][c2] != 'X' && cnt(r2, c2) < 2 || r1 == r2 && c1 == c2 && cnt(r2, c2) == 0){
			out.println("NO");
		}
		else{
			g[r2][c2] = '.';
			dfs(r1, c1);
			out.println(g[r2][c2] == '!'?"YES":"NO");
		}
		out.flush();
		out.close();
	}

	static char[][] g;
	static int r2, c2;

	static void dfs(int i, int j) {
		g[i][j] = '!';
		if (i == r2 && j == c2)
			return;
		for (int k = 0; k < dx.length; k++) {
			int nx = i + dx[k], ny = j + dy[k];
			if (val(nx, ny)){
				dfs(nx, ny);
			}
		}
	}

	static int[] dx = { 1, 0, -1, 0 };
	static int[] dy = { 0, -1, 0, 1 };

	static int cnt(int i, int j) {
		int res = 0;
		for (int j2 = 0; j2 < dx.length; j2++) {
			int nx = i + dx[j2], ny = j + dy[j2];
			if (val(nx, ny))
				res++;

		}
		return res;
	}

	static boolean val(int i, int j) {
		return i >= 0 && j >= 0 && i < g.length && j < g[i].length && g[i][j] == '.';
	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}


//package CF;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), m = sc.nextInt();
		g = new char[n][m];
		for (int i = 0; i < g.length; i++) {
			g[i] = sc.next().toCharArray();
		}
		int r1 = sc.nextInt()-1, c1 = sc.nextInt()-1;
		 r2 = sc.nextInt()-1; c2 = sc.nextInt()-1;
		if(!((cnt(r2, c2) >= 1 && g[r2][c2] == 'X') || cnt(r2, c2) >= 2)){
			out.println("NO");
		}
		else{
			g[r2][c2] = '.';
			dfs(r1, c1);
			out.println(g[r2][c2] == '!'?"YES":"NO");
		}
		out.flush();
		out.close();
	}

	static char[][] g;
	static int r2, c2;

	static void dfs(int i, int j) {
		g[i][j] = '!';
		if (i == r2 && j == c2)
			return;
		for (int k = 0; k < dx.length; k++) {
			int nx = i + dx[k], ny = j + dy[k];
			if (val(nx, ny))
				dfs(nx, ny);
		}
	}

	static int[] dx = { 1, 0, -1, 0 };
	static int[] dy = { 0, -1, 0, 1 };

	static int cnt(int i, int j) {
		int res = 0;
		for (int j2 = 0; j2 < dx.length; j2++) {
			int nx = i + dx[j2], ny = j + dy[j2];
			if (val(nx, ny))
				res++;

		}
		return res;
	}

	static boolean val(int i, int j) {
		return i >= 0 && j >= 0 && i < g.length && j < g[i].length && g[i][j] == '.';
	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Temp {
	class FastSolver {
		int[] dx = { 1, -1, 0, 0 };
		int[] dy = { 0, 0, 1, -1 };
		boolean found = false;
		boolean ok = false;

		boolean inBounds(int x, int y, int n, int m) {
			if (x >= n || x < 0 || y >= m || y < 0)
				return false;
			return true;
		}

		public boolean canReach(int x, int y, int ex, int ey, int n, int m,
				char[][] map) {
			if (x == ex && y == ey) {
				return true;
			}
			map[x][y] = 'o';
			boolean result = false;
			for (int i = 0; i < 4; i++) {
				int r = x + dx[i];
				int c = y + dy[i];
				if (inBounds(r, c, n, m)) {
					if (r == ex && c == ey)
						return true;
					if (map[r][c] == '.')
						result |= canReach(r, c, ex, ey, n, m, map);
				}
			}

			return result;
		}

		public void Solve() {
			int n = ni();
			int m = ni();
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = n().toCharArray();
			}

			int r1 = ni() - 1;
			int c1 = ni() - 1;
			int r2 = ni() - 1;
			int c2 = ni() - 1;
			int count = 0;
			// System.out.println(r1 + " " + c1 + " :: " + r2 + " " + c2);
			for (int i = 0; i < 4; i++) {
				int r = r2 + dx[i];
				int c = c2 + dy[i];
				// System.out.println("r: " + r + " c: " + c);
				if (inBounds(r, c, n, m) && map[r][c] == '.') {
					count++;
				}
				if(r==r1&&c==c1)
					count++;
			}
			// System.out.println(count);
			if (count < 2 && map[r2][c2] == '.') {
				System.out.println("NO");
				return;
			}
			if (r1 == r2 && c1 == c2) {
				if (count > 0) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
				return;
			}
			if (canReach(r1, c1, r2, c2, n, m, map)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

		BufferedReader br;
		StringTokenizer st;

		public FastSolver(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String n() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		String l() {
			String s = null;
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;

		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nb() {
			return Integer.parseInt(n(), 2);
		}

		long nbl() {
			return Long.parseLong(n(), 2);
		}

		int ni() {
			return Integer.parseInt(n());
		}

		double nd() {
			return Double.parseDouble(n());
		}

		long nl() {
			return Long.parseLong(n());
		}
	}

	public void run() {
		FastSolver in = new FastSolver(System.in);
		PrintWriter out = new PrintWriter(System.out);
		in.Solve();
		out.close();
	}

	public static void main(String[] args) {
		new Temp().run();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Temp {
	class FastSolver {
		int[] dx = { 1, -1, 0, 0 };
		int[] dy = { 0, 0, 1, -1 };
		boolean found = false;
		boolean ok = false;

		boolean inBounds(int x, int y, int n, int m) {
			if (x >= n || x < 0 || y >= m || y < 0)
				return false;
			return true;
		}

		public boolean canReach(int x, int y, int ex, int ey, int n, int m,
				char[][] map) {
			if (x == ex && y == ey) {
				return true;
			}
			map[x][y] = 'o';
			boolean result = false;
			for (int i = 0; i < 4; i++) {
				int r = x + dx[i];
				int c = y + dy[i];
				if (inBounds(r, c, n, m)) {
					if (r == ex && c == ey)
						return true;
					if (map[r][c] == '.')
						result |= canReach(r, c, ex, ey, n, m, map);
				}
			}

			return result;
		}

		public void Solve() {
			int n = ni();
			int m = ni();
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = n().toCharArray();
			}

			int r1 = ni() - 1;
			int c1 = ni() - 1;
			int r2 = ni() - 1;
			int c2 = ni() - 1;
			int count = 0;
			// System.out.println(r1 + " " + c1 + " :: " + r2 + " " + c2);
			for (int i = 0; i < 4; i++) {
				int r = r2 + dx[i];
				int c = c2 + dy[i];
				// System.out.println("r: " + r + " c: " + c);
				if (inBounds(r, c, n, m) && map[r][c] == '.') {
					count++;
				}
			}
			// System.out.println(count);
			if (count < 2 && map[r2][c2] == '.') {
				System.out.println("NO");
				return;
			}
			if (r1 == r2 && c1 == c2) {
				if (count > 0) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
				return;
			}
			if (canReach(r1, c1, r2, c2, n, m, map)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

		BufferedReader br;
		StringTokenizer st;

		public FastSolver(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String n() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		String l() {
			String s = null;
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;

		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nb() {
			return Integer.parseInt(n(), 2);
		}

		long nbl() {
			return Long.parseLong(n(), 2);
		}

		int ni() {
			return Integer.parseInt(n());
		}

		double nd() {
			return Double.parseDouble(n());
		}

		long nl() {
			return Long.parseLong(n());
		}
	}

	public void run() {
		FastSolver in = new FastSolver(System.in);
		PrintWriter out = new PrintWriter(System.out);
		in.Solve();
		out.close();
	}

	public static void main(String[] args) {
		new Temp().run();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Temp {
	class FastSolver {
		int[] dx = { 1, -1, 0, 0 };
		int[] dy = { 0, 0, 1, -1 };
		boolean found = false;
		boolean ok = false;

		boolean inBounds(int x, int y, int n, int m) {
			if (x >= n || x < 0 || y >= m || y < 0)
				return false;
			return true;
		}

		public boolean canReach(int x, int y, int ex, int ey, int n, int m,
				char[][] map) {

			if (!inBounds(x, y, n, m)) {
				return false;
			}
			map[x][y] = 'o';
			if (x == ex && y == ey) {
				return true;
			}
			if (map[x][y] == 'X') {
				return false;
			}
			boolean result = false;
			for (int i = 0; i < 4; i++) {
				int r = x + dx[i];
				int c = y + dy[i];
				if (inBounds(r, c, n, m) && map[r][c] != 'o') {

				result |= canReach(r, c, ex, ey, n, m, map);
				}
			}

			return result;
		}

		public void Solve() {
			int n = ni();
			int m = ni();
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = n().toCharArray();
			}

			int r1 = ni() - 1;
			int c1 = ni() - 1;
			int r2 = ni() - 1;
			int c2 = ni() - 1;
			int count = 0;
			//System.out.println(r1 + " " + c1 + " :: " + r2 + " " + c2);
			for (int i = 0; i < 4; i++) {
				int r = r2 + dx[i];
				int c = c2 + dy[i];
				//System.out.println("r: " + r + " c: " + c);
				if (inBounds(r, c, n, m) && map[r][c] == '.') {
					count++;
				}
			}
		//	System.out.println(count);
			if (count < 2 && map[r2][c2] == '.') {
				System.out.println("NO");
				return;
			}
			if (canReach(r1, c1, r2, c2, n, m, map)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

		BufferedReader br;
		StringTokenizer st;

		public FastSolver(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String n() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		String l() {
			String s = null;
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;

		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nb() {
			return Integer.parseInt(n(), 2);
		}

		long nbl() {
			return Long.parseLong(n(), 2);
		}

		int ni() {
			return Integer.parseInt(n());
		}

		double nd() {
			return Double.parseDouble(n());
		}

		long nl() {
			return Long.parseLong(n());
		}
	}

	public void run() {
		FastSolver in = new FastSolver(System.in);
		PrintWriter out = new PrintWriter(System.out);
		in.Solve();
		out.close();
	}

	public static void main(String[] args) {
		new Temp().run();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Temp {
	class FastSolver {
		int[] dx = { 1, -1, 0, 0 };
		int[] dy = { 0, 0, 1, -1 };
		boolean found = false;
		boolean ok = false;

		boolean inBounds(int x, int y, int n, int m) {
			if (x >= n || x < 0 || y >= m || y < 0)
				return false;
			return true;
		}

		public boolean canReach(int x, int y, int ex, int ey, int n, int m,
				char[][] map) {

			if (!inBounds(x, y, n, m)) {
				return false;
			}

			if (x == ex && y == ey) {
				return true;
			}
			if (map[x][y] == 'X') {
				map[x][y] = 'o';
				return false;
			}
			map[x][y] = 'o';
			boolean result = false;
			for (int i = 0; i < 4; i++) {
				int r = x + dx[i];
				int c = y + dy[i];
				if (inBounds(r, c, n, m) && map[r][c] != 'o') {

					result |= canReach(r, c, ex, ey, n, m, map);
				}
			}

			return result;
		}

		public void Solve() {
			int n = ni();
			int m = ni();
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = n().toCharArray();
			}

			int r1 = ni() - 1;
			int c1 = ni() - 1;
			int r2 = ni() - 1;
			int c2 = ni() - 1;
			int count = 0;
			// System.out.println(r1 + " " + c1 + " :: " + r2 + " " + c2);
			for (int i = 0; i < 4; i++) {
				int r = r2 + dx[i];
				int c = c2 + dy[i];
				// System.out.println("r: " + r + " c: " + c);
				if (inBounds(r, c, n, m) && map[r][c] == '.') {
					count++;
				}
			}
			// System.out.println(count);
			if (count < 2 && map[r2][c2] == '.') {
				System.out.println("NO");
				return;
			}
			if (r1 == r2 && c1 == c2) {
				if (count > 0) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
				return;
			}
			if (canReach(r1, c1, r2, c2, n, m, map)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

		BufferedReader br;
		StringTokenizer st;

		public FastSolver(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String n() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		String l() {
			String s = null;
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;

		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nb() {
			return Integer.parseInt(n(), 2);
		}

		long nbl() {
			return Long.parseLong(n(), 2);
		}

		int ni() {
			return Integer.parseInt(n());
		}

		double nd() {
			return Double.parseDouble(n());
		}

		long nl() {
			return Long.parseLong(n());
		}
	}

	public void run() {
		FastSolver in = new FastSolver(System.in);
		PrintWriter out = new PrintWriter(System.out);
		in.Solve();
		out.close();
	}

	public static void main(String[] args) {
		new Temp().run();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Temp {
	class FastSolver {
		int[] dx = { 1, -1, 0, 0 };
		int[] dy = { 0, 0, 1, -1 };
		boolean found = false;
		boolean ok = false;

		boolean inBounds(int x, int y, int n, int m) {
			if (x >= n || x < 0 || y >= m || y < 0)
				return false;
			return true;
		}

		public boolean canReach(int x, int y, int ex, int ey, int n, int m,
				char[][] map) {

			if (!inBounds(x, y, n, m)) {
				return false;
			}
			map[x][y] = 'o';
			if (x == ex && y == ey) {
				return true;
			}
			if (map[x][y] == 'X') {
				return false;
			}
			boolean result = false;
			for (int i = 0; i < 4; i++) {
				int r = x + dx[i];
				int c = y + dy[i];
				if (inBounds(r, c, n, m) && map[r][c] != 'o') {

					result |= canReach(r, c, ex, ey, n, m, map);
				}
			}

			return result;
		}

		public void Solve() {
			int n = ni();
			int m = ni();
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = n().toCharArray();
			}

			int r1 = ni() - 1;
			int c1 = ni() - 1;
			int r2 = ni() - 1;
			int c2 = ni() - 1;
			int count = 0;
			// System.out.println(r1 + " " + c1 + " :: " + r2 + " " + c2);
			for (int i = 0; i < 4; i++) {
				int r = r2 + dx[i];
				int c = c2 + dy[i];
				// System.out.println("r: " + r + " c: " + c);
				if (inBounds(r, c, n, m) && map[r][c] == '.') {
					count++;
				}
			}
			// System.out.println(count);
			if (count < 2 && map[r2][c2] == '.') {
				System.out.println("NO");
				return;
			}
			if (r1 == r2 && c1 == c2) {
				if (count > 0) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
				return;
			}
			if (canReach(r1, c1, r2, c2, n, m, map)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

		BufferedReader br;
		StringTokenizer st;

		public FastSolver(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String n() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		String l() {
			String s = null;
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;

		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nb() {
			return Integer.parseInt(n(), 2);
		}

		long nbl() {
			return Long.parseLong(n(), 2);
		}

		int ni() {
			return Integer.parseInt(n());
		}

		double nd() {
			return Double.parseDouble(n());
		}

		long nl() {
			return Long.parseLong(n());
		}
	}

	public void run() {
		FastSolver in = new FastSolver(System.in);
		PrintWriter out = new PrintWriter(System.out);
		in.Solve();
		out.close();
	}

	public static void main(String[] args) {
		new Temp().run();
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CIceCave solver = new CIceCave();
        solver.solve(1, in, out);
        out.close();
    }

    static class CIceCave {
        private int n;
        private int m;
        private char[][] arr;
        private boolean[][] vis;
        private int[] row = new int[]{-1, 0, 1, 0};
        private int[] col = new int[]{0, 1, 0, -1};

        private boolean isValid(int x, int y) {
            return x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && arr[x][y] == '.';
        }

        private boolean isValid2(int x, int y) {
            return x >= 1 && x <= n && y >= 1 && y <= m && arr[x][y] == '.';
        }

        private void floodFlill(int x, int y) {
            vis[x][y] = true;
            for (int i = 0; i < 4; i++) {
                if (isValid(x + row[i], y + col[i])) floodFlill(x + row[i], y + col[i]);
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            arr = new char[n + 1][m + 1];
            vis = new boolean[n + 1][m + 1];
            for (int i = 1; i <= n; i++) {
                String str = in.nextLine();
                for (int j = 1; j <= m; j++) {
                    arr[i][j] = str.charAt(j - 1);
                }
            }
            int r1 = in.nextInt(), c1 = in.nextInt();
            int r2 = in.nextInt(), c2 = in.nextInt();

            if (r1 == r2 && c1 == c2) {
                int cnt = 0;
                if (isValid2(r2 - 1, c2)) cnt++;
                if (isValid2(r2 + 1, c2)) cnt++;
                if (isValid2(r2, c2 - 1)) cnt++;
                if (isValid2(r2, c2 + 1)) cnt++;
                if (cnt > 0) {
                    out.println("YES");
                    return;
                } else {
                    out.println("NO");
                    return;
                }
            }
            boolean once = false;
            if (arr[r2][c2] == 'X') once = true;

            arr[r2][c2] = '.';
            arr[r1][c1] = '.';
            floodFlill(r1, c1);
//        for (int i=0; i<=n; i++) out.println(Arrays.toString(vis[i]));
            if (!vis[r2][c2]) {
                out.println("NO");
                return;
            }
            if (once) {
                out.println("YES");
                return;
            }

            int cnt = 0;
            if (isValid2(r2 - 1, c2)) cnt++;
            if (isValid2(r2 + 1, c2)) cnt++;
            if (isValid2(r2, c2 - 1)) cnt++;
            if (isValid2(r2, c2 + 1)) cnt++;

            if (cnt >= 2) out.println("YES");
            else out.println("NO");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CIceCave solver = new CIceCave();
        solver.solve(1, in, out);
        out.close();
    }

    static class CIceCave {
        private int n;
        private int m;
        private char[][] arr;
        private boolean[][] vis;
        private int[] row = new int[]{-1, 0, 1, 0};
        private int[] col = new int[]{0, 1, 0, -1};

        private boolean isValid(int x, int y) {
            return x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && arr[x][y] == '.';
        }

        private boolean isValid2(int x, int y) {
            return x >= 1 && x <= n && y >= 1 && y <= m && arr[x][y] == '.';
        }

        private void floodFlill(int x, int y) {
            vis[x][y] = true;
            for (int i = 0; i < 4; i++) {
                if (isValid(x + row[i], y + col[i])) floodFlill(x + row[i], y + col[i]);
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            arr = new char[n + 1][m + 1];
            vis = new boolean[n + 1][m + 1];
            for (int i = 1; i <= n; i++) {
                String str = in.nextLine();
                for (int j = 1; j <= m; j++) {
                    arr[i][j] = str.charAt(j - 1);
                }
            }
            int r1 = in.nextInt(), c1 = in.nextInt();
            int r2 = in.nextInt(), c2 = in.nextInt();
            boolean once = false;
            if (arr[r2][c2] == 'X') once = true;

            arr[r2][c2] = '.';
            floodFlill(r1, c1);

            if (!vis[r2][c2]) {
                out.println("NO");
                return;
            }
            if (once) {
                out.println("YES");
                return;
            }

            int cnt = 0;
            if (isValid2(r2 - 1, c2)) cnt++;
            if (isValid2(r2 + 1, c2)) cnt++;
            if (isValid2(r2, c2 - 1)) cnt++;
            if (isValid2(r2, c2 + 1)) cnt++;

            if (cnt >= 2) out.println("YES");
            else out.println("NO");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CIceCave solver = new CIceCave();
        solver.solve(1, in, out);
        out.close();
    }

    static class CIceCave {
        private int n;
        private int m;
        private char[][] arr;
        private boolean[][] vis;
        private int[] row = new int[]{-1, 0, 1, 0};
        private int[] col = new int[]{0, 1, 0, -1};

        private boolean isValid(int x, int y) {
            return x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && arr[x][y] == '.';
        }

        private boolean isValid2(int x, int y) {
            return x >= 1 && x <= n && y >= 1 && y <= m && arr[x][y] == '.';
        }

        private void floodFlill(int x, int y) {
            vis[x][y] = true;
            for (int i = 0; i < 4; i++) {
                if (isValid(x + row[i], y + col[i])) floodFlill(x + row[i], y + col[i]);
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            arr = new char[n + 1][m + 1];
            vis = new boolean[n + 1][m + 1];
            for (int i = 1; i <= n; i++) {
                String str = in.nextLine();
                for (int j = 1; j <= m; j++) {
                    arr[i][j] = str.charAt(j - 1);
                }
            }
            int r1 = in.nextInt(), c1 = in.nextInt();
            int r2 = in.nextInt(), c2 = in.nextInt();

            if (r1 == r2 && c1 == c2) {
                int cnt = 0;
                if (isValid2(r2 - 1, c2)) cnt++;
                if (isValid2(r2 + 1, c2)) cnt++;
                if (isValid2(r2, c2 - 1)) cnt++;
                if (isValid2(r2, c2 + 1)) cnt++;
                if (cnt > 0) {
                    out.println("YES");
                    return;
                } else {
                    out.println("NO");
                    return;
                }
            }
            boolean once = false;
            if (arr[r2][c2] == 'X') once = true;

            arr[r2][c2] = '.';
            floodFlill(r1, c1);

            if (!vis[r2][c2]) {
                out.println("NO");
                return;
            }
            if (once) {
                out.println("YES");
                return;
            }

            int cnt = 0;
            if (isValid2(r2 - 1, c2)) cnt++;
            if (isValid2(r2 + 1, c2)) cnt++;
            if (isValid2(r2, c2 - 1)) cnt++;
            if (isValid2(r2, c2 + 1)) cnt++;

            if (cnt >= 2) out.println("YES");
            else out.println("NO");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	private static int[] start, goal;
	private static final int[][] DIR = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();

		char[][] map = new char[H + 2][];
		map[0] = new char[W + 2];
		map[H + 1] = new char[W + 2];
		Arrays.fill(map[0], 'X');
		Arrays.fill(map[H + 1], 'X');
		for (int i = 1; i <= H; i++) {
			map[i] = ("X" + sc.next() + "X").toCharArray();
		}
		start = new int[2];
		for (int i = 0; i < 2; i++) {
			start[i] = sc.nextInt();
		}
		goal = new int[2];
		for (int i = 0; i < 2; i++) {
			goal[i] = sc.nextInt();
		}

		// ゴールが割れやすい氷の時
		if (map[goal[0]][goal[1]] == 'X') {
			boolean canArrive = false;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					canArrive = true;
					break;
				}
			}
			if (!canArrive) {
				System.out.println("NO");
				return;
			}
		} else {
			int around = 0;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					around++;
				}
			}
			if (around < 2) {
				System.out.println("NO");
				return;
			}
		}

		boolean[][] visited = new boolean[H + 2][W + 2];
		Deque<Now> bfsDeque = new ArrayDeque<>();
		bfsDeque.add(new Now(start[0], start[1], map));
		visited[start[0]][start[1]] = true;

		while (!bfsDeque.isEmpty()) {
			Now now = bfsDeque.poll();
			for (int d = 0; d < DIR.length; d++) {
				int x = now.x + DIR[d][0];
				int y = now.y + DIR[d][1];
				if (x == goal[0] && y == goal[1]) {
					System.out.println("YES");
					return;
				}
				if (now.nowMap[x][y] == 'X' || visited[x][y]) {
					continue;
				}

				now.nowMap[x][y] = 'X';
				bfsDeque.add(new Now(x, y, now.nowMap));
				visited[x][y] = true;
				now.nowMap[x][y] = '.';
			}
		}
		System.out.println("NO");

	}
}

class Now {
	char[][] nowMap;
	int x, y;

	public Now(int x, int y, char[][] m) {
		this.x = x;
		this.y = y;

		this.nowMap = new char[m.length][];
		for (int i = 0; i < m.length; i++) {
			this.nowMap[i] = String.valueOf(m[i]).toCharArray();
		}
	}

}


import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	private static int[] start, goal;
	private static final int[][] DIR = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();

		char[][] map = new char[H + 2][];
		map[0] = new char[W + 2];
		map[H + 1] = new char[W + 2];
		Arrays.fill(map[0], 'X');
		Arrays.fill(map[H + 1], 'X');
		for (int i = 1; i <= H; i++) {
			map[i] = ("X" + sc.next() + "X").toCharArray();
		}
		start = new int[2];
		for (int i = 0; i < 2; i++) {
			start[i] = sc.nextInt();
		}
		goal = new int[2];
		for (int i = 0; i < 2; i++) {
			goal[i] = sc.nextInt();
		}
		sc.close();

		// ゴールが割れやすい氷の時
		if (map[goal[0]][goal[1]] == 'X') {
			boolean canArrive = false;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					canArrive = true;
					break;
				}
			}
			if (!canArrive) {
				System.out.println("NO");
				return;
			}
		} else {
			int around = 0;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					around++;
				}
			}
			if (around < 2) {
				System.out.println("NO");
				return;
			}
		}

		boolean[][] visited = new boolean[H + 2][W + 2];
		Deque<Integer[]> bfsDeque = new ArrayDeque<>();
		bfsDeque.add(new Integer[] { start[0], start[1] });
		visited[start[0]][start[1]] = true;

		while (!bfsDeque.isEmpty()) {
			Integer[] now = bfsDeque.poll();

			for (int d = 0; d < DIR.length; d++) {
				int x = now[0] + DIR[d][0];
				int y = now[1] + DIR[d][1];
				if (x == goal[0] && y == goal[1]) {
					System.out.println("YES");
					return;
				}
				if (map[x][y] == 'X' || visited[x][y]) {
					continue;
				}

				bfsDeque.add(new Integer[] { x, y });
				visited[x][y] = true;
			}
		}
		System.out.println("NO");

	}
}


import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	private static int[] start, goal;
	private static final int[][] DIR = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();

		char[][] map = new char[H + 2][];
		map[0] = new char[W + 2];
		map[H + 1] = new char[W + 2];
		Arrays.fill(map[0], 'X');
		Arrays.fill(map[H + 1], 'X');
		for (int i = 1; i <= H; i++) {
			map[i] = ("X" + sc.next() + "X").toCharArray();
		}
		start = new int[2];
		for (int i = 0; i < 2; i++) {
			start[i] = sc.nextInt();
		}
		goal = new int[2];
		for (int i = 0; i < 2; i++) {
			goal[i] = sc.nextInt();
		}
		sc.close();

		// ゴールが割れやすい氷の時
		if (map[goal[0]][goal[1]] == 'X') {
			if (Math.abs(start[0] - goal[0]) + Math.abs(start[1] - goal[1]) == 1) {
				System.out.println("YES");
				return;
			}
			boolean canArrive = false;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					canArrive = true;
					break;
				}
			}
			if (!canArrive) {
				System.out.println("NO");
				return;
			}
		} else {
			int around = 0;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					around++;
				}
			}
			if (around < 2) {
				System.out.println("NO");
				return;
			} else if (Math.abs(start[0] - goal[0]) + Math.abs(start[1] - goal[1]) == 1 && around >= 1) {
				System.out.println("YES");
				return;
			}
		}

		boolean[][] visited = new boolean[H + 2][W + 2];
		Deque<Integer[]> bfsDeque = new ArrayDeque<>();
		bfsDeque.add(new Integer[] { start[0], start[1] });
		visited[start[0]][start[1]] = true;

		while (!bfsDeque.isEmpty()) {
			Integer[] now = bfsDeque.poll();

			for (int d = 0; d < DIR.length; d++) {
				int x = now[0] + DIR[d][0];
				int y = now[1] + DIR[d][1];
				if (x == goal[0] && y == goal[1]) {
					System.out.println("YES");
					return;
				}
				if (map[x][y] == 'X' || visited[x][y]) {
					continue;
				}

				bfsDeque.add(new Integer[] { x, y });
				visited[x][y] = true;
			}
		}
		System.out.println("NO");

	}
}


import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	private static int[] start, goal;
	private static final int[][] DIR = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();

		char[][] map = new char[H + 2][];
		map[0] = new char[W + 2];
		map[H + 1] = new char[W + 2];
		Arrays.fill(map[0], 'X');
		Arrays.fill(map[H + 1], 'X');
		for (int i = 1; i <= H; i++) {
			map[i] = ("X" + sc.next() + "X").toCharArray();
		}
		start = new int[2];
		for (int i = 0; i < 2; i++) {
			start[i] = sc.nextInt();
		}
		goal = new int[2];
		for (int i = 0; i < 2; i++) {
			goal[i] = sc.nextInt();
		}
		sc.close();

		// ゴールが割れやすい氷の時
		if (map[goal[0]][goal[1]] == 'X') {
			if (Math.abs(start[0] - goal[0]) + Math.abs(start[1] - goal[1]) == 1) {
				System.out.println("YES");
				return;
			}
			boolean canArrive = false;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					canArrive = true;
					break;
				}
			}
			if (!canArrive) {
				System.out.println("NO");
				return;
			}
		} else {
			int around = 0;
			for (int d = 0; d < DIR.length; d++) {
				int x = goal[0] + DIR[d][0];
				int y = goal[1] + DIR[d][1];
				if (map[x][y] == '.') {
					around++;
				}
			}
			if (Math.abs(start[0] - goal[0]) + Math.abs(start[1] - goal[1]) == 1 && around >= 1) {
				System.out.println("YES");
				return;
			} else if (around < 2) {
				System.out.println("NO");
				return;
			}
		}

		boolean[][] visited = new boolean[H + 2][W + 2];
		Deque<Integer[]> bfsDeque = new ArrayDeque<>();
		bfsDeque.add(new Integer[] { start[0], start[1] });
		visited[start[0]][start[1]] = true;

		while (!bfsDeque.isEmpty()) {
			Integer[] now = bfsDeque.poll();

			for (int d = 0; d < DIR.length; d++) {
				int x = now[0] + DIR[d][0];
				int y = now[1] + DIR[d][1];
				if (x == goal[0] && y == goal[1]) {
					System.out.println("YES");
					return;
				}
				if (map[x][y] == 'X' || visited[x][y]) {
					continue;
				}

				bfsDeque.add(new Integer[] { x, y });
				visited[x][y] = true;
			}
		}
		System.out.println("NO");

	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static int[] start, goal;
	private static final int[][] DIR = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();

		char[][] map = new char[H + 2][];
		map[0] = new char[W + 2];
		map[H + 1] = new char[W + 2];
		Arrays.fill(map[0], 'X');
		Arrays.fill(map[H + 1], 'X');
		for (int i = 1; i <= H; i++) {
			map[i] = ("X" + sc.next() + "X").toCharArray();
		}
		start = new int[2];
		for (int i = 0; i < 2; i++) {
			start[i] = sc.nextInt();
		}
		goal = new int[2];
		for (int i = 0; i < 2; i++) {
			goal[i] = sc.nextInt();
		}

		if (dfs(new Now(start[0], start[1], map))) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	static boolean dfs(Now now) {
		for (int d = 0; d < DIR.length; d++) {
			int x = now.x + DIR[d][0];
			int y = now.y + DIR[d][1];
			if (now.nowMap[x][y] == 'X') {
				if (x == goal[0] && y == goal[1]) {
					return true;
				}
				continue;
			}

			now.nowMap[x][y] = 'X';
			if (dfs(new Now(x, y, now.nowMap))) {
				return true;
			}
			now.nowMap[x][y] = '.';
		}
		return false;
	}
}

class Now {
	char[][] nowMap;
	int x, y;

	public Now(int x, int y, char[][] m) {
		this.x = x;
		this.y = y;

		this.nowMap = new char[m.length][];
		for (int i = 0; i < m.length; i++) {
			this.nowMap[i] = String.valueOf(m[i]).toCharArray();
		}
	}

}


import java.util.Arrays;
import java.util.Scanner;

public class C {

    int n, m, si, sj, gi, gj;
    char[][] map;
    int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};

    boolean dfs(int i, int j){
        if (i==gi && j==gj && map[i][j]=='X')return true;
        map[i][j] = 'X';
        for(int k=0;k<4;k++){
            int ni = i+d[k][0], nj = j+d[k][1];
            if ((ni==gi&&nj==gj) || map[ni][nj]=='.'){
                if (dfs(ni, nj))return true;
            }
        }
        map[i][j] = '.';
        return false;
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); m = sc.nextInt();
        map = new char[n+2][m+2];
        for(char[] c:map)Arrays.fill(c, 'X');
        for(int i=1;i<=n;i++){
            char[] s = sc.next().toCharArray();
            for(int j=0;j<m;j++)map[i][j+1] = s[j];
        }
        si = sc.nextInt(); sj = sc.nextInt(); gi = sc.nextInt(); gj = sc.nextInt();
        System.out.println(dfs(si, sj)?"YES":"NO");
    }

    void debug(Object...o){
        System.out.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new C().run();
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class C {

    int n, m, si, sj, gi, gj;
    char[][] map;
    int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};

    boolean dfs(int i, int j){
        if (i==gi && j==gj && map[i][j]=='X')return true;
        map[i][j] = 'X';
        for(int k=0;k<4;k++){
            int ni = i+d[k][0], nj = j+d[k][1];
            if ((ni==gi&&nj==gj) || map[ni][nj]=='.'){
                if (dfs(ni, nj))return true;
            }
        }
        map[i][j] = '.';
        return false;
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); m = sc.nextInt();
        map = new char[n+2][m+2];
        for(char[] c:map)Arrays.fill(c, 'X');
        for(int i=1;i<=n;i++){
            char[] s = sc.next().toCharArray();
            for(int j=0;j<m;j++)map[i][j+1] = s[j];
        }
        si = sc.nextInt(); sj = sc.nextInt(); gi = sc.nextInt(); gj = sc.nextInt();
        map[si][sj] = '.';
        System.out.println(dfs(si, sj)?"YES":"NO");
    }

    void debug(Object...o){
        System.out.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new C().run();
    }
}


import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class C {

    int n, m, si, sj, gi, gj;
    char[][] map;
    int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};
    int[][] dist;

    class R implements Comparable<R>{
        int idx, dd;
        public R(int idx, int dd) {
            this.idx = idx;
            this.dd = dd;
        }
        @Override
        public int compareTo(R o) {
            return dd-o.dd;
        }
    }

    boolean dfs(int i, int j){
        if (i==gi && j==gj && map[i][j]=='X')return true;
        map[i][j] = 'X';
        R[] r = new R[4];
        for(int k=0;k<4;k++){
            int ni = i+d[k][0], nj = j+d[k][1];
            r[k] = new R(k, dist[ni][nj]);
        }
        Arrays.sort(r);
        for(R rr:r){
            int ni = i+d[rr.idx][0], nj = j+d[rr.idx][1];
            if ((ni==gi&&nj==gj) || map[ni][nj]=='.'){
                if (dfs(ni, nj))return true;
            }
        }
        map[i][j] = '.';
        return false;
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); m = sc.nextInt();
        map = new char[n+2][m+2];
        for(char[] c:map)Arrays.fill(c, 'X');
        for(int i=1;i<=n;i++){
            char[] s = sc.next().toCharArray();
            for(int j=0;j<m;j++)map[i][j+1] = s[j];
        }
        si = sc.nextInt(); sj = sc.nextInt(); gi = sc.nextInt(); gj = sc.nextInt();
        dist = new int[n+2][m+2];
        for(int[]a:dist)Arrays.fill(a, 1<<29);
        Queue<int[]> q = new LinkedList<int[]>();
        dist[gi][gj] = 0;
        q.add(new int[]{gi, gj});
        while(!q.isEmpty()){
            int[] u = q.poll();
            for(int k=0;k<4;k++){
                int ni = u[0]+d[k][0], nj = u[1]+d[k][1];
                if ((map[ni][nj]=='.' || (ni==si&&nj==sj)) && dist[ni][nj]==1<<29){
                    dist[ni][nj] = dist[u[0]][u[1]]+1;
                    q.add(new int[]{ni, nj});
                }
            }
        }
        if (dist[si][sj] == 1<<29){
            System.out.println("NO"); return;
        }
        int degree = 0;
        for(int k=0;k<4;k++){
            int ni = gi+d[k][0], nj=gj+d[k][1];
            if(map[ni][nj]=='.' || (si==ni&&sj==nj))degree++;
        }
        if (map[gi][gj]=='.' && degree < 2 || map[gi][gj]=='X' && degree < 1){
            System.out.println("NO"); return;
        }
        map[si][sj] = '.';
        System.out.println(dfs(si, sj)?"YES":"NO");
    }

    void debug(Object...o){
        System.out.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new C().run();
    }
}


import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class C {

    int n, m, si, sj, gi, gj;
    char[][] map;
    int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};
    int[][] dist;

    class R implements Comparable<R>{
        int idx, dd;
        public R(int idx, int dd) {
            this.idx = idx;
            this.dd = dd;
        }
        @Override
        public int compareTo(R o) {
            return dd-o.dd;
        }
    }

    boolean dfs(int i, int j){
        if (i==gi && j==gj && map[i][j]=='X')return true;
        map[i][j] = 'X';
        R[] r = new R[4];
        for(int k=0;k<4;k++){
            int ni = i+d[k][0], nj = j+d[k][1];
            r[k] = new R(k, dist[ni][nj]);
        }
        Arrays.sort(r);
        for(R rr:r){
            int ni = i+d[rr.idx][0], nj = j+d[rr.idx][1];
            if ((ni==gi&&nj==gj) || map[ni][nj]=='.'){
                if (dfs(ni, nj))return true;
            }
        }
        map[i][j] = '.';
        return false;
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); m = sc.nextInt();
        map = new char[n+2][m+2];
        for(char[] c:map)Arrays.fill(c, 'X');
        for(int i=1;i<=n;i++){
            char[] s = sc.next().toCharArray();
            for(int j=0;j<m;j++)map[i][j+1] = s[j];
        }
        si = sc.nextInt(); sj = sc.nextInt(); gi = sc.nextInt(); gj = sc.nextInt();
        dist = new int[n+2][m+2];
        for(int[]a:dist)Arrays.fill(a, 1<<29);
        Queue<int[]> q = new LinkedList<int[]>();
        dist[gi][gj] = 0;
        q.add(new int[]{gi, gj});
        while(!q.isEmpty()){
            int[] u = q.poll();
            for(int k=0;k<4;k++){
                int ni = u[0]+d[k][0], nj = u[1]+d[k][1];
                if ((map[ni][nj]=='.' || (ni==si&&nj==sj)) && dist[ni][nj]==1<<29){
                    dist[ni][nj] = dist[u[0]][u[1]]+1;
                    q.add(new int[]{ni, nj});
                }
            }
        }
        if (dist[si][sj] == 1<<29){
            System.out.println("NO"); return;
        }
        int degree = 0;
        for(int k=0;k<4;k++){
            int ni = gi+d[k][0], nj=gj+d[k][1];
            if(map[ni][nj]=='.')degree++;
        }
        if (map[gi][gj]=='.' && degree < 2 || map[gi][gj]=='X' && degree < 1){
            System.out.println("NO"); return;
        }
        map[si][sj] = '.';
        System.out.println(dfs(si, sj)?"YES":"NO");
    }

    void debug(Object...o){
        System.out.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new C().run();
    }
}


In English  По-русски
ericly | Logout

HOMECONTESTSGYMPROBLEMSETGROUPSRATINGAPIHELPTESTLIBVK CUP 2016 CROC 2016

PROBLEMSSUBMIT CODEMY SUBMISSIONSSTATUSSTANDINGSCUSTOM INVOCATION

General

#	Author	Problem	Lang	Verdict	Time	Memory	Sent	Judged
11406393	Practice:
ericly	203345L - 39	Java 8	Accepted	171 ms	0 KB	2015-06-03 22:37:22	2015-06-03 22:37:22	 Add to favourites	Compare

→ Source
import java.util.*;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.PrintWriter;

public class a
{
	public static void main(String[] arg)
	{
		new a();
	}
	public a()
	{
		//JoltyScanner in = new JoltyScanner(System.in);
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int row = in.nextInt();
		int col = in.nextInt();
		char[][] grid = new char[row][col];
		for(int i = 0; i < row; i++) grid[i] = in.next().toCharArray();
		Pair source = new Pair(in.nextInt()-1, in.nextInt()-1);
		Pair sink = new Pair(in.nextInt()-1, in.nextInt()-1);
		int check = findIntact(grid, sink, row, col);
		boolean flag = false;
		if(source.equals(sink))
		{
			if(check >= 1) flag = true;
			else flag = false;
		}
		else if(source.adjacent(sink))
		{
			if(grid[sink.row][sink.col] == 'X') flag = true;
			else
			{
				if(check >= 2) flag = true;
				else if(check >= 1 && grid[source.row][source.col] == 'X') flag = true;
				else flag = false;
			}
		}
		else
		{
			if(findPath(source, sink, grid))
			{
				if(grid[sink.row][sink.col] == 'X') flag = true;
				else
				{
					if(check >= 2) flag = true;
					else flag = false;
				}
			}
			else flag = false;
		}
		System.out.println(flag ? "YES" : "NO");
		in.close();
		out.close();
	}
	public boolean findPath(Pair start, Pair end, char[][] grid)
	{
		ArrayDeque<Pair> q = new ArrayDeque<Pair>();
		q.add(start);
		boolean answer = false;
		int[] dx = {0 ,0, -1, 1};
		int[] dy = {-1, 1, 0, 0};
		while(q.size() > 0)
		{
			Pair temp = q.poll();
			if(!temp.isValid(grid)) continue;
			if(temp.equals(end)) return true;
			if(!temp.equals(start) && grid[temp.row][temp.col] == 'X') continue;
			grid[temp.row][temp.col] = 'X';
			for(int i = 0; i < 4; i++)
			{
				q.add(new Pair(temp.row+dx[i], temp.col+dy[i]));
			}
		}
		return answer;
	}
	public int findIntact(char[][] grid, Pair cur, int maxRow, int maxCol)
	{
		int answer = 0;
		int x = cur.row;
		int y = cur.col;
		if(x != 0)
			if(grid[x-1][y] == '.') answer++;

		if(x != maxRow-1)
			if(grid[x+1][y] == '.') answer++;

		if(y != 0)
			if(grid[x][y-1] == '.') answer++;

		if(y != maxCol-1)
			if(grid[x][y+1] == '.') answer++;

		return answer;
	}
	class Pair
	{
		public int row, col;
		public Pair(int a, int b)
		{
			row = a;
			col = b;
		}
		public boolean equals(Pair a)
		{
			return row == a.row && col == a.col;
		}
		public boolean adjacent(Pair a)
		{
			return Math.abs(row-a.row) + Math.abs(col-a.col) == 1;
		}
		public boolean isValid(char[][] grid)
		{
			if(row < 0 || row >= grid.length) return false;
			if(col < 0 || col >= grid[row].length) return false;
			return true;
		}
	}
	public class JoltyScanner
	{
	    public static final int BUFFER_SIZE = 1 << 16;
		public static final char NULL_CHAR = (char) -1;

	    byte[] buffer = new byte[BUFFER_SIZE];
		boolean EOF_FLAG = false;
		int bufferIdx = 0, size = 0;
		char c = NULL_CHAR;
		BufferedInputStream in;

		public JoltyScanner(InputStream in)
		{
			this.in = new BufferedInputStream(in, BUFFER_SIZE);
		}

		public int nextInt()
		{
			long x = nextLong();
			if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE)
			{
				throw new ArithmeticException("Scanned value overflows integer");
			}
			return (int) x;
		}

		public long nextLong()
		{
			boolean negative = false;
			if (c == NULL_CHAR)
			{
				c = nextChar();
			}
			for (; !EOF_FLAG && (c < '0' || c > '9'); c = nextChar())
			{
				if (c == '-')
				{
					negative = true;
				}
			}
			checkEOF();
			long res = 0;
			for (; c >= '0' && c <= '9'; c = nextChar())
			{
				res = (res << 3) + (res << 1) + c - '0';
			}
			return negative ? -res : res;
		}

	    public char nextChar()
	    {
			if (EOF_FLAG)
			{
				return NULL_CHAR;
			}
			while (bufferIdx == size)
			{
				try
				{
					size = in.read(buffer);
					if (size == -1)
					{
						throw new Exception();
					}
				}
				catch (Exception e)
				{
					EOF_FLAG = true;
					return NULL_CHAR;
				}
				if (size == -1)
				{
					size = BUFFER_SIZE;
				}
				bufferIdx = 0;
			}
			return (char) buffer[bufferIdx++];
		}

	    public void checkEOF()
	    {
			if (EOF_FLAG)
			{
				throw new EndOfFileException();
			}
		}

		public class EndOfFileException extends RuntimeException
		{
		}
	}
}

/*
1 2
.X
1 2
1 1
NO

1 2
.X
1 2
1 2
YES

1 1
X
1 1
1 1

1 2
XX
1 1
1 1
NO
*/
Codeforces (c) Copyright 2010-2016 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Mar/02/2016 18:02:06UTC-5 (c3).
Desktop version, switch to mobile version.


import java.util.*;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.PrintWriter;

public class a
{
	public static void main(String[] arg)
	{
		new a();
	}
	public a()
	{
		//JoltyScanner in = new JoltyScanner(System.in);
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int row = in.nextInt();
		int col = in.nextInt();
		char[][] grid = new char[row][col];
		for(int i = 0; i < row; i++) grid[i] = in.next().toCharArray();
		Pair source = new Pair(in.nextInt()-1, in.nextInt()-1);
		Pair sink = new Pair(in.nextInt()-1, in.nextInt()-1);
		int check = findIntact(grid, sink, row, col);
		boolean flag = false;
		if(source.equals(sink))
		{
			if(check >= 1) flag = true;
			else flag = false;
		}
		else if(source.adjacent(sink))
		{
			if(grid[sink.row][sink.col] == 'X') flag = true;
			else
			{
				if(check >= 2) flag = true;
				else if(check >= 1 && grid[source.row][source.col] == 'X') flag = true;
				else flag = false;
			}
		}
		else
		{
			if(findPath(source, sink, grid))
			{
				if(grid[sink.row][sink.col] == 'X') flag = true;
				else
				{
					if(check >= 2) flag = true;
					else flag = false;
				}
			}
			else flag = false;
		}
		System.out.println(flag ? "YES" : "NO");
		in.close();
		out.close();
	}
	public boolean findPath(Pair start, Pair end, char[][] grid)
	{
		ArrayDeque<Pair> q = new ArrayDeque<Pair>();
		q.add(start);
		boolean answer = false;
		int[] dx = {0 ,0, -1, 1};
		int[] dy = {-1, 1, 0, 0};
		while(q.size() > 0)
		{
			Pair temp = q.poll();
			if(!temp.isValid(grid)) continue;
			if(temp.equals(end)) return true;
			if(!temp.equals(start) && grid[temp.row][temp.col] == 'X') continue;
			grid[temp.row][temp.col] = 'X';
			for(int i = 0; i < 4; i++)
			{
				q.add(new Pair(temp.row+dx[i], temp.col+dy[i]));
			}
		}
		return answer;
	}
	public int findIntact(char[][] grid, Pair cur, int maxRow, int maxCol)
	{
		int answer = 0;
		int x = cur.row;
		int y = cur.col;
		if(x != 0)
			if(grid[x-1][y] == '.') answer++;

		if(x != maxRow-1)
			if(grid[x+1][y] == '.') answer++;

		if(y != 0)
			if(grid[x][y-1] == '.') answer++;

		if(y != maxCol-1)
			if(grid[x][y+1] == '.') answer++;

		return answer;
	}
	class Pair
	{
		public int row, col;
		public Pair(int a, int b)
		{
			row = a;
			col = b;
		}
		public boolean equals(Pair a)
		{
			return row == a.row && col == a.col;
		}
		public boolean adjacent(Pair a)
		{
			return Math.abs(row-a.row) + Math.abs(col-a.col) == 1;
		}
		public boolean isValid(char[][] grid)
		{
			if(row < 0 || row >= grid.length) return false;
			if(col < 0 || col >= grid[row].length) return false;
			return true;
		}
	}
	public class JoltyScanner
	{
	    public static final int BUFFER_SIZE = 1 << 16;
		public static final char NULL_CHAR = (char) -1;

	    byte[] buffer = new byte[BUFFER_SIZE];
		boolean EOF_FLAG = false;
		int bufferIdx = 0, size = 0;
		char c = NULL_CHAR;
		BufferedInputStream in;

		public JoltyScanner(InputStream in)
		{
			this.in = new BufferedInputStream(in, BUFFER_SIZE);
		}

		public int nextInt()
		{
			long x = nextLong();
			if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE)
			{
				throw new ArithmeticException("Scanned value overflows integer");
			}
			return (int) x;
		}

		public long nextLong()
		{
			boolean negative = false;
			if (c == NULL_CHAR)
			{
				c = nextChar();
			}
			for (; !EOF_FLAG && (c < '0' || c > '9'); c = nextChar())
			{
				if (c == '-')
				{
					negative = true;
				}
			}
			checkEOF();
			long res = 0;
			for (; c >= '0' && c <= '9'; c = nextChar())
			{
				res = (res << 3) + (res << 1) + c - '0';
			}
			return negative ? -res : res;
		}

	    public char nextChar()
	    {
			if (EOF_FLAG)
			{
				return NULL_CHAR;
			}
			while (bufferIdx == size)
			{
				try
				{
					size = in.read(buffer);
					if (size == -1)
					{
						throw new Exception();
					}
				}
				catch (Exception e)
				{
					EOF_FLAG = true;
					return NULL_CHAR;
				}
				if (size == -1)
				{
					size = BUFFER_SIZE;
				}
				bufferIdx = 0;
			}
			return (char) buffer[bufferIdx++];
		}

	    public void checkEOF()
	    {
			if (EOF_FLAG)
			{
				throw new EndOfFileException();
			}
		}

		public class EndOfFileException extends RuntimeException
		{
		}
	}
}