题目:藏宝图

typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
const int mod  = 1e9 + 7;
/**
 * 不要使用#define int long long
 * 不开long long见祖宗
 *                  ----YuFei Zhou
 */
 struct box{
     int x,y;
 };
 int dx[4] = {0,0,1,-1};
 int dy[4] = {-1,1,0,0};
 map<pair<int,int>,int> vt;
vector<string> g;
int n,m;
int ans1,ans2;
 void bfs(int x,int y){
     queue<box> q;
     box tmp;
     tmp.x = x;
     tmp.y = y;
     q.push(tmp);
     ans1++;
     int tt = 0;
     if(g[x][y] > '1'){
         tt = 1;
     }
     vt[{x,y}] = 1;
     while (!q.empty()){
         tmp = q.front();
         q.pop();
         for (int i = 0; i < 4; ++i) {
             int tx = tmp.x + dx[i];
             int ty = tmp.y + dy[i];
             if(tx >= 1 && tx <= n && ty >= 1 && ty <= m && vt[{tx,ty}] == 0 && g[tx][ty] != '0'){
                 vt[{tx,ty}] = 1;
                 if(g[tx][ty] > '1'){
                     tt = 1;
                 }
                 q.push({tx, ty});
             }
         }
     }
     ans2 += tt;
 }
void solve() {
    cin>>n>>m;
    g.push_back(" ");
    for (int i = 1; i <= n; ++i) {
        string s;
        cin>>s;
        s = " " + s;
        g.push_back(s);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if(g[i][j]  != '0' && vt[{i,j}] == 0){
                bfs(i,j);
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();//1 2 3 4 5
    }
    return 0 ;
}