# 找能去的所有0区域

给一个二维matrix，-1代表墙，0代表路。问给定一个起点坐标为0，是否能到达所有的0。

```
public class AllReachableZero {
    

    public boolean findAllReachableZero(int[][] matrix, int x, int y)
    {
        boolean[][] visited = new boolean[matrix.length][matrix[0].length];
        dfs(matrix, x, y, visited);
        for(int i = 0; i< matrix.length; i++)
        {
            for(int j = 0; j< matrix[0].length; j++)
            {
                if(!visited[i][j] && matrix[i][j] == 0)
                {
                    return false;
                }
            }
        }
        return true;
    }

    public void dfs(int[][] matrix, int i, int j, boolean[][] visited)
    {
        if(!isBound(matrix, i, j) || visited[i][j] || matrix[i][j] == -1 || matrix[i][j] == 1)
        {
            return;
        }

        visited[i][j] = true;
        matrix[i][j] = 1;
        dfs(matrix, i-1, j, visited);
        dfs(matrix, i+1, j, visited);
        dfs(matrix, i, j-1, visited);
        dfs(matrix, i, j+1, visited);
    }

    public boolean isBound(int[][] matrix, int i, int j)
    {
        return i>=0 && i<matrix.length && j>=0 && j<matrix[0].length;
    }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://junnie.gitbook.io/wayfair/oa/karat/zhao-neng-qu-de-suo-you-0-qu-yu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
