c++ solution using bfs
\nclass Solution {\npublic:\n    int trapRainWater(vector<vector<int>>& mat)\n    {\n        int n=mat.size();\n        int m=mat[0].size();\n        priority_q
```\nclass Solution {\npublic:\n    int trapRainWater(vector<vector<int>>& mat)\n    {\n        int n=mat.size();\n        int m=mat[0].size();\n        priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>>pq;\n        vector<vector<bool>>vis(n,vector<bool>(m,false));\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                if(i==0||j==0||i==n-1||j==m-1)\n                {\n                    pq.push({mat[i][j],{i,j}});\n                    vis[i][j]=true;\n                }\n            }\n        }\n        vector<pair<int,int>>d={{-1,0},{1,0},{0,-1},{0,1}};\n    int ans=0;\n        while(pq.size())\n        {\n            auto temp=pq.top();\n            pq.pop();\n            int val=temp.first;\n            int x=temp.second.first;\n            int y=temp.second.second;\n            for(auto it:d)\n            {\n                int nx=x+it.first;\n                int ny=y+it.second;\n                if(nx>=0&&ny>=0&&nx<n&&ny<m&&vis[nx][ny]==false)\n                {\n                    vis[nx][ny]=true;\n                    ans+=max(0,val-mat[nx][ny]);\n                    pq.push({max(val,mat[nx][ny]),{nx,ny}});\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'C', 'C++']