Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=405;
int n,size,head[maxn],dis[maxn][maxn];
struct edge
{
	int to,next;
}E[maxn*2];
inline void add(int u,int v)
{
	E[++size].to=v;
	E[size].next=head[u];
	head[u]=size;
	dis[u][v]=dis[v][u]=1;
}
bool color[maxn],vis[maxn];
inline bool check()
{
	queue<int>Q;
	Q.push(1);
	vis[1]=1;
	while(!Q.empty())
	{
		int u=Q.front();
		Q.pop();
		for(int i=head[u];i;i=E[i].next)
		{
			int v=E[i].to;
			if(vis[v]&&color[u]==color[v])
				return false;
			else if(!vis[v])
			{
				vis[v]=1,color[v]=1-color[u];
				Q.push(v);
			}
		}
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			dis[i][j]=dis[j][i]=n+1;
	for(int i=1;i<=n;++i)
	{
		string s;
		cin>>s;
		for(int j=0;j<n;++j)
			if(s[j]=='1')
				add(i,j+1),add(j+1,i);
	}
	if(!check())
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			ans=max(ans,dis[i][j]);
	cout<<ans+1<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'void add(int, int)':
a.cc:11:13: error: reference to 'size' is ambiguous
   11 |         E[++size].to=v;
      |             ^~~~
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:4:7: note:                 'int size'
    4 | int n,size,head[maxn],dis[maxn][maxn];
      |       ^~~~
a.cc:12:11: error: reference to 'size' is ambiguous
   12 |         E[size].next=head[u];
      |           ^~~~
/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:4:7: note:                 'int size'
    4 | int n,size,head[maxn],dis[maxn][maxn];
      |       ^~~~
a.cc:13:17: error: reference to 'size' is ambiguous
   13 |         head[u]=size;
      |                 ^~~~
/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:4:7: note:                 'int size'
    4 | int n,size,head[maxn],dis[maxn][maxn];
      |       ^~~~