Language: C++

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

int w,h;
vector<string> ss;
bool write[52][52];
bool black[52][52];

void dfs(int x_,int y_,bool (*f_)[52],bool f2) {
    //cout<<x_<<","<<y_<<endl;
    if(f_[x_][y_]||(ss[x_][y_]!='.'&&f2)) return;
    f_[x_][y_]=true;
    rep(i,4) {
        int x = x_ + dx[i];
        int y = y_ + dy[i];
        if(0<=x&&x<ss.size() && 0<=y&&y<ss[x].size()) {
            dfs(x,y,f_,true);
        }
    }
}

void solve() {
    rep(i,52) rep(j,52) write[i][j]=black[i][j]=false;
    ss.resize(w);
    rep(i,h) {
        string t; cin>>t;
        ss[i] = t;
    }
    int ans_b=0,ans_w=0;
    rep(i,ss.size()) {
        rep(j,ss[i].size()) {
            if(ss[i][j]=='B') dfs(i,j,black,false);
            if(ss[i][j]=='W') dfs(i,j,write,false);
        }
    }
    rep(i,ss.size()) rep(j,ss[i].size()) {
        //cout<<i<<","<<j<<":"<<write[i][j]<<","<<black[i][j]<<ss[i][j]<<endl;
        if(ss[i][j]=='.'&&(write[i][j]^black[i][j])) {
           if(write[i][j]) ans_w++;
           else ans_b++; 
        }
    }
    cout<<ans_b<<" "<<ans_w<<endl;
    ss.clear();
}

int main() {
    while(cin>>w>>h) {
        if(w+h==0) return 0;
        solve();
    }

    return 0;
}

Compiler output:
a.cc:10:18: error: 'bool write [52][52]' redeclared as different kind of entity
   10 | bool write[52][52];
      |                  ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:378:16: note: previous declaration 'ssize_t write(int, const void*, size_t)'
  378 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
      |                ^~~~~
a.cc: In function 'void solve()':
a.cc:27:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   27 |     rep(i,52) rep(j,52) write[i][j]=black[i][j]=false;
      |                                ^
a.cc:27:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   27 |     rep(i,52) rep(j,52) write[i][j]=black[i][j]=false;
      |                                   ^
a.cc:27:36: error: assignment of read-only location '*(write + (((sizetype)i) + ((sizetype)j)))'
   27 |     rep(i,52) rep(j,52) write[i][j]=black[i][j]=false;
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc:37:34: error: cannot convert 'ssize_t (*)(int, const void*, size_t)' {aka 'long int (*)(int, const void*, long unsigned int)'} to 'bool (*)[52]'
   37 |             if(ss[i][j]=='W') dfs(i,j,write,false);
      |                               ~~~^~~~~~~~~~~~~~~~~
      |                                  |
      |                                  ssize_t (*)(int, const void*, size_t) {aka long int (*)(int, const void*, long unsigned int)}
a.cc:13:31: note:   initializing argument 3 of 'void dfs(int, int, bool (*)[52], bool)'
   13 | void dfs(int x_,int y_,bool (*f_)[52],bool f2) {
      |                        ~~~~~~~^~~~~~~
a.cc:42:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   42 |         if(ss[i][j]=='.'&&(write[i][j]^black[i][j])) {
      |                                   ^
a.cc:42:38: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   42 |         if(ss[i][j]=='.'&&(write[i][j]^black[i][j])) {
      |                                      ^
a.cc:42:39: error: invalid operands of types 'ssize_t(int, const void*, size_t)' {aka 'long int(int, const void*, long unsigned int)'} and 'bool' to binary 'operator^'
   42 |         if(ss[i][j]=='.'&&(write[i][j]^black[i][j])) {
      |                            ~~~~~~~~~~~^~~~~~~~~~~~
      |                                      |           |
      |                                      |           bool
      |                                      ssize_t(int, const void*, size_t) {aka long int(int, const void*, long unsigned int)}
a.cc:43:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   43 |            if(write[i][j]) ans_w++;
      |                      ^
a.cc:43:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   43 |            if(write[i][j]) ans_w++;
      |                         ^