Very Concise C++ solution using DFS and bit mask
\nclass Solution {\npublic:\n    vector<pair<int, int>> res;\n    vector<vector<int>> visited;\n    void dfs(vector<vector<int>>& matrix, int x, int y, int pre,
```\nclass Solution {\npublic:\n    vector<pair<int, int>> res;\n    vector<vector<int>> visited;\n    void dfs(vector<vector<int>>& matrix, int x, int y, int pre, int preval){\n        if (x < 0 || x >= matrix.size() || y < 0 || y >= matrix[0].size()  \n                || matrix[x][y] < pre || (visited[x][y] & preval) == preval) \n            return;\n        visited[x][y] |= preval;\n        if (visited[x][y] == 3) res.push_back({x, y});\n        dfs(matrix, x + 1, y, matrix[x][y], visited[x][y]); dfs(matrix, x - 1, y, matrix[x][y], visited[x][y]);\n        dfs(matrix, x, y + 1, matrix[x][y], visited[x][y]); dfs(matrix, x, y - 1, matrix[x][y], visited[x][y]);\n    }\n\n    vector<pair<int, int>> pacificAtlantic(vector<vector<int>>& matrix) {\n        if (matrix.empty()) return res;\n        int m = matrix.size(), n = matrix[0].size();\n        visited.resize(m, vector<int>(n, 0));\n        for (int i = 0; i < m; i++) {\n            dfs(matrix, i, 0, INT_MIN, 1);\n            dfs(matrix, i, n - 1, INT_MIN, 2);\n        }\n        for (int i = 0; i < n; i++) {\n            dfs(matrix, 0, i, INT_MIN, 1);\n            dfs(matrix, m - 1, i, INT_MIN, 2);\n        }\n        return res;\n    }\n};\n```
[]