Language: C++

#include <iostream>
#include <string>
using namespace std;
long matrix[400][400] = {};
long count_matrix[400][400] = {};
int H, W, route_count = 0;
void black(int i, int j);
void white(int i, int j);

void black(int i, int j){
  matrix[i][j] = 10;
  if(i - 1 >= 0){
    if(matrix[i - 1][j] == -2) white(i-1, j);
  }
  if(i + 1 < H){
    if(matrix[i + 1][j] == -2) white(i+1, j);
  }
  if(j - 1 >= 0){
    if(matrix[i][j - 1] == -2) white(i, j-1);
  }
  if(j + 1 < W){
    if(matrix[i][j + 1] == -2) white(i, j+1);
  }
  matrix[i][j] = -1;
}

void white(int i, int j){
  count_matrix[i][j] = 1;
  matrix[i][j] = 10;
  if(i - 1 >= 0){
    if(matrix[i - 1][j] == -1) black(i-1, j);
  }
  if(i + 1 < H){
    if(matrix[i + 1][j] == -1) black(i+1, j);
  }
  if(j - 1 >= 0){
    if(matrix[i][j - 1] == -1) black(i, j-1);
  }
  if(j + 1 < W){
    if(matrix[i][j + 1] == -1) black(i, j+1);
  }
  matrix[i][j] = -2;
}

void reset_count_matrix(){  //count_matrixの値をすべてゼロにする(初期化)
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count_matrix[i][j] = 0;
    }
  }
}

void counter(){  //countに組み合わせ数を加算する
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(count_matrix[i][j] == 1){
        route_count++;
    }
  }
}

int main() {
  cin >> H >> W;
  string S[400] = {};
 
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#')matrix[i][j] = -1;
      else if (S[i][j] == '.')matrix[i][j] = -2;
      else matrix[i][j] = -100;
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(matrix[i][j] == -1) {  //黒の場合だけカウントをスタートする
        reset_count_matrix();
        black(i, j);
        counter();
      }
    }
  }

  cout << route_count <<endl;
}#include <iostream>
#include <string>
using namespace std;
long matrix[400][400] = {};
long count_matrix[400][400] = {};
int H, W, route_count = 0;
void black(int i, int j);
void white(int i, int j);

void black(int i, int j){
  matrix[i][j] = 10;
  if(i - 1 >= 0){
    if(matrix[i - 1][j] == -2) white(i-1, j);
  }
  if(i + 1 < H){
    if(matrix[i + 1][j] == -2) white(i+1, j);
  }
  if(j - 1 >= 0){
    if(matrix[i][j - 1] == -2) white(i, j-1);
  }
  if(j + 1 < W){
    if(matrix[i][j + 1] == -2) white(i, j+1);
  }
  matrix[i][j] = -1;
}

void white(int i, int j){
  count_matrix[i][j] = 1;
  matrix[i][j] = 10;
  if(i - 1 >= 0){
    if(matrix[i - 1][j] == -1) black(i-1, j);
  }
  if(i + 1 < H){
    if(matrix[i + 1][j] == -1) black(i+1, j);
  }
  if(j - 1 >= 0){
    if(matrix[i][j - 1] == -1) black(i, j-1);
  }
  if(j + 1 < W){
    if(matrix[i][j + 1] == -1) black(i, j+1);
  }
  matrix[i][j] = -2;
}

void reset_count_matrix(){  //count_matrixの値をすべてゼロにする(初期化)
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count_matrix[i][j] = 0;
    }
  }
}

void counter(){  //countに組み合わせ数を加算する
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(count_matrix[i][j] == 1){
        route_count++;
    }
  }
}

int main() {
  cin >> H >> W;
  string S[400] = {};
 
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#')matrix[i][j] = -1;
      else if (S[i][j] == '.')matrix[i][j] = -2;
      else matrix[i][j] = -100;
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(matrix[i][j] == -1) {  //黒の場合だけカウントをスタートする
        reset_count_matrix();
        black(i, j);
        counter();
      }
    }
  }

  cout << route_count <<endl;
}

Compiler output:
a.cc:89:2: error: stray '#' in program
   89 | }#include <iostream>
      |  ^
a.cc: In function 'void counter()':
a.cc:62:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   62 | int main() {
      |         ^~
a.cc:62:9: note: remove parentheses to default-initialize a variable
   62 | int main() {
      |         ^~
      |         --
a.cc:62:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:62:12: error: a function-definition is not allowed here before '{' token
   62 | int main() {
      |            ^
a.cc:89:3: error: 'include' was not declared in this scope
   89 | }#include <iostream>
      |   ^~~~~~~
a.cc:89:20: error: expected primary-expression before '>' token
   89 | }#include <iostream>
      |                    ^
a.cc:91:1: error: expected primary-expression before 'using'
   91 | using namespace std;
      | ^~~~~
a.cc:98:25: error: a function-definition is not allowed here before '{' token
   98 | void black(int i, int j){
      |                         ^
a.cc:115:25: error: a function-definition is not allowed here before '{' token
  115 | void white(int i, int j){
      |                         ^
a.cc:133:26: error: a function-definition is not allowed here before '{' token
  133 | void reset_count_matrix(){  //count_matrixの値をすべてゼロにする(初期化)
      |                          ^
a.cc:141:15: error: a function-definition is not allowed here before '{' token
  141 | void counter(){  //countに組み合わせ数を加算する
      |               ^
a.cc:177:2: error: expected '}' at end of input
  177 | }
      |  ^
a.cc:53:15: note: to match this '{'
   53 | void counter(){  //countに組み合わせ数を加算する
      |               ^