Language: C++

#include <iostream>
#include <vector>
#include <map>

using namespace std;

vector<pair<int,int>> d(4);
d[0] = make_pair(1,0);
d[1] = make_pair(0,1);
d[2] = make_pair(-1,0);
d[3] = make_pair(0,-1);

int check(int w, int h, vector<vector<char>> &V, vector<vector<bool>> &C){
  int tmp = 1;
  //黒の連結成分に含まれる黒の数をadjにpush_back
    for(int i = 0; i < 4; i++){
      int wp = w + d[i].first;
      int hp = h + d[i].second;
      if(wp < 0 || wp > W - 1 || hp < 0 || hp > H - 1)continue;
      if(V[wp][hp] == '#'){
        tmp += check(wp, hp);
        C[wp,hp] = true;
      }
    }
  return tmp;
}

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> V(H,vector<char> (W,'x'));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> V[i][j];
    }
  }
  vector<int> adj;
  vector<vector<bool>> C(H,vector<bool> (W,false));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(C[i][j])continue;
      if(C[i][j] == '#'){
      adj.push_back(check(i ,j ,V, C));
      }
      C[i][j] = true;
    }
  }
  sort(adj.begin(), adj.end());
  if(adj[0] <= 1) cout << "Yes";
  else cout << "No";
}

Compiler output:
a.cc:8:1: error: 'd' does not name a type
    8 | d[0] = make_pair(1,0);
      | ^
a.cc:9:1: error: 'd' does not name a type
    9 | d[1] = make_pair(0,1);
      | ^
a.cc:10:1: error: 'd' does not name a type
   10 | d[2] = make_pair(-1,0);
      | ^
a.cc:11:1: error: 'd' does not name a type
   11 | d[3] = make_pair(0,-1);
      | ^
a.cc: In function 'int check(int, int, std::vector<std::vector<char> >&, std::vector<std::vector<bool> >&)':
a.cc:19:25: error: 'W' was not declared in this scope
   19 |       if(wp < 0 || wp > W - 1 || hp < 0 || hp > H - 1)continue;
      |                         ^
a.cc:19:49: error: 'H' was not declared in this scope
   19 |       if(wp < 0 || wp > W - 1 || hp < 0 || hp > H - 1)continue;
      |                                                 ^
a.cc:21:21: error: too few arguments to function 'int check(int, int, std::vector<std::vector<char> >&, std::vector<std::vector<bool> >&)'
   21 |         tmp += check(wp, hp);
      |                ~~~~~^~~~~~~~
a.cc:13:5: note: declared here
   13 | int check(int w, int h, vector<vector<char>> &V, vector<vector<bool>> &C){
      |     ^~~~~
a.cc:22:20: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<bool> >, std::vector<bool> >::value_type' {aka 'std::vector<bool>'} and 'bool')
   22 |         C[wp,hp] = true;
      |                    ^~~~
In file included from /usr/include/c++/14/vector:67,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_bvector.h:894:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(const std::vector<bool, _Alloc>&) [with _Alloc = std::allocator<bool>]'
  894 |       operator=(const vector& __x)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:894:31: note:   no known conversion for argument 1 from 'bool' to 'const std::vector<bool>&'
  894 |       operator=(const vector& __x)
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:926:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::vector<bool, _Alloc>&&) [with _Alloc = std::allocator<bool>]'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:926:26: note:   no known conversion for argument 1 from 'bool' to 'std::vector<bool>&&'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:952:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::initializer_list<bool>) [with _Alloc = std::allocator<bool>]'
  952 |       operator=(initializer_list<bool> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:952:40: note:   no known conversion for argument 1 from 'bool' to 'std::initializer_list<bool>'
  952 |       operator=(initializer_list<bool> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc: In function 'int main()':
a.cc:48:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   48 |   sort(adj.begin(), adj.end());
      |   ^~~~
      |   short