Language: C++

#include<bits/stdc++.h>

using namespace std;
typedef long long unsigned int ll;
int h,w;
vector<string> fi;


int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};



int par[200005];//iの一つ上にあるやつ
int r[200005];//iの属するグループの"大きさ"（計算を速くするため）

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        r[i]=0;
    }
}//全部バラバラの状態

int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}//一番上の付け根を求める

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    
    if(r[x]<r[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(r[x]==r[y]) r[x]++;
    }
}//xとyのグループを付け根でくっつける

bool same(int x,int y){
    return find(x)==find(y);
}//同じグループにいるかどうか

//void dfs(int sx,int sy){
    
    
//}

int main(){
    cin>>h>>w;
    fi.resize(h);
    for(int i=0;i<h;i++){
        cin>>fi[i];
    }
    init(h*w);
   
    
    
    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            for(int dir=0;dir<4;dir++){
                
                int nx=x+dx[dir];
                int ny=y+dy[dir];
                if(nx>=0&&nx<h&&ny>=0&&ny<w){
                    if(fi[x][y]!=fi[nx][ny]){
                        unite(x*w+y,nx*w+ny);
                    }
                }
            }
        }
    }
    
    int ans=0;
    map<int,int> black,white,mp;
    for(int x=0;x<h;x++){
        for(int y=0;y<w;y++){
            mp[find(x*w+y)]=1;
            if(fi[x][y]=='#') black[find(x*w+y)]++;
            else white[find(x*w+y)]++;
        }
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        ans+=black[itr]*white[itr];
    }
    
    
    cout<<ans<<endl;
    return 0;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:89:19: error: no match for 'operator[]' (operand types are 'std::map<int, int>' and 'std::_Rb_tree_iterator<std::pair<const int, int> >')
   89 |         ans+=black[itr]*white[itr];
      |                   ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; mapped_type = int; key_type = int]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::_Rb_tree_iterator<std::pair<const int, int> >' to 'const std::map<int, int>::key_type&' {aka 'const int&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; mapped_type = int; key_type = int]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::_Rb_tree_iterator<std::pair<const int, int> >' to 'std::map<int, int>::key_type&&' {aka 'int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:89:30: error: no match for 'operator[]' (operand types are 'std::map<int, int>' and 'std::_Rb_tree_iterator<std::pair<const int, int> >')
   89 |         ans+=black[itr]*white[itr];
      |                              ^
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; mapped_type = int; key_type = int]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::_Rb_tree_iterator<std::pair<const int, int> >' to 'const std::map<int, int>::key_type&' {aka 'const int&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; mapped_type = int; key_type = int]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::_Rb_tree_iterator<std::pair<const int, int> >' to 'std::map<int, int>::key_type&&' {aka 'int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~