Language: C++

#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
#define con(x,y)	((x)*(m)+(y))
using namespace std;

int dsu[MAX];
int size[MAX];

int search(int a)	{
	if(dsu[a]==a)	return a;
	return dsu[a]=search(dsu[a]);
}

void join(int a, int b)	{
	a = search(a);
	b = search(b);
	if(size[a]<size[b])	{
		dsu[b]=a;
		size[a]+=size[b];
	}
	else {
		dsu[a]=b;
		size[b]+=size[a];
	}
}

void solve()	{
	int n,m;
	cin >> n >> m;
	string s[n];
	for(int i=0; i<m*n; i++)	{
		size[i]=1;
		dsu[i]=i;
	}
	for(int i=0; i<n; i++)	cin >> s[i];
	for(int i=0; i<n; i++)	{
		for(int j=0; j<m; j++)	{
			//cout << con(i,j) << endl;
			if(j+1<m && s[i][j]=='#' && s[i][j+1]=='#')	{
				if(search(con(i,j))!=search(con(i,j+1)))	
					join(con(i,j),con(i,j+1));
			}
			if(i+1<n && s[i][j]=='#' && s[i+1][j]=='#')	{
				if(search(con(i,j))!=search(con(i+1,j)))
					join(con(i,j),con(i+1,j));
			}
		}
	}
	bool f=0;
	for(int i=0; i<n; i++)	{
		for(int j=0; j<m; j++)	{
			if(s[i][j]=='#')	{
				if(size[search(con(i,j))]==1)	{
					f=1; break;
				}
			}
		}
	}
	if(f)	cout << "No\n";
	else cout << "Yes\n";
}

int main()	
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Compiler output:
a.cc: In function 'void join(int, int)':
a.cc:21:12: error: reference to 'size' is ambiguous
   21 |         if(size[a]<size[b])     {
      |            ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~
a.cc:21:20: error: reference to 'size' is ambiguous
   21 |         if(size[a]<size[b])     {
      |                    ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~
a.cc:23:17: error: reference to 'size' is ambiguous
   23 |                 size[a]+=size[b];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~
a.cc:23:26: error: reference to 'size' is ambiguous
   23 |                 size[a]+=size[b];
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~
a.cc:27:17: error: reference to 'size' is ambiguous
   27 |                 size[b]+=size[a];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~
a.cc:27:26: error: reference to 'size' is ambiguous
   27 |                 size[b]+=size[a];
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~
a.cc: In function 'void solve()':
a.cc:36:17: error: reference to 'size' is ambiguous
   36 |                 size[i]=1;
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~
a.cc:57:36: error: reference to 'size' is ambiguous
   57 |                                 if(size[search(con(i,j))]==1)   {
      |                                    ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:11:5: note:                 'int size [1000005]'
   11 | int size[MAX];
      |     ^~~~