Language: C++

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
#define int ll
class UnionFind {
private:
	vector<vector<int>> Graph;// {ID,Number,ParentID,Height}
public:
	void Init(int n) {
		for (int x = 0; x < n; x++) {
			push(x);
		}
	}
	void push(int x) {
		int i = Graph.size();
		Graph.push_back({ i,x,i,1 });
	}
	void unite(int x, int y) {
		int hx = Graph[root(x)][3];
		int hy = Graph[root(y)][3];
		if (hx < hy) {
			Graph[root(x)][2] = root(y);
			flatten(x, root(y));
		}
		else if (hx == hy) {
			Graph[root(y)][2] = root(x);
			Graph[root(x)][3]++;
			flatten(y, root(x));
		}
		else {
			Graph[root(y)][2] = root(x);
			flatten(y, root(x));
		}
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void flatten(int x, int rootid) {
		int parentid = Graph[x][0];
		while (Graph[parentid][0] != Graph[parentid][2]) {
			Graph[parentid][2] = rootid;
			int next = Graph[parentid][2];
			parentid = next;
		}
	}
	int root(int x) {
		int parentid = Graph[x][0];
		while (Graph[parentid][0] != Graph[parentid][2]) {
			int next = Graph[parentid][2];
			parentid = next;
		}

		return parentid;
	}
};

vector<int> operator+(const vi& v1, const vi& v2) {
	return { v1[0] + v2[0],v1[1] + v2[1] };
}

class Table {
public:
	vector<vector<int>> vec;
	vector<vector<int>> isVisited;
	vector<vector<int>> moves = { {1,0},{-1,0},{0,1},{0,-1} };
	vector<vector<int>> group;
	UnionFind uf;
	int h, w;
public:
	Table(int H, int W) {
		uf.Init(H * W);
		h = H;
		w = W;
		vec.resize(H,vi(W)); 
		isVisited.resize(H,vi(W,false));
		group.resize(H,vi(W));
		for (int i = 0; i < H; i++) {
			string s; cin >> s;
			for (int j = 0; j < W; j++) {
				if (s[j] == '.') vec[i][j] = 1;
				else vec[i][j] = -1;
				group[i][j] = W * i + j;
			}
		}

	}

	bool DoesExist(vi c1) {// DFS
		stack<vi> st;
		st.push(c1);
		isVisited[c1[0]][c1[1]] = true;
		while (!st.empty()) {
			vi u = st.top(); st.pop();
			for (int i = 0; i < 4; i++) {
				vi v = u + moves[i];
				//Coordinate Validation
				if (v[0] < 0 || v[1] < 0 || v[0] == h || v[1] == w) continue;
				//
				if (vec[v[0]][v[1]] * vec[u[0]][u[1]] == -1 && isVisited[v[0]][v[1]] == false && group[v[0]][v[1]] == w*v[0] + v[1]) {
					uf.unite(w * v[0] + v[1], w * u[0] + u[1]);

					st.push(v);
					isVisited[v[0]][v[1]] = true;
				}
			}
		}

		return false;
	}

	void AllUnite() {
		
	}
};

ll main() {
	int H, W; cin >> H >> W;
	Table tb(H, W);

	//All Search
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			tb.DoesExist({ i,j });
		}
	}
	vector<vector<int>> res(H *W,vi(2)); //{white,black} for each node
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int rt = tb.uf.root(W * i + j);
			if (tb.vec[i][j] == 1) {// white
				res[rt][0]++;
			}
			else {
				res[rt][1]++;
			}
		}
	}

	ll ans = 0;
	for (int t = 0; t < H * W; t++) {
		ans += res[t][0] * res[t][1];
	}


	cout << ans << endl;
}

Compiler output:
cc1plus: error: '::main' must return 'int'