Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (10000000000000000ll)
#define mod (1000000007)

int n;
bool g[222][222];
bool ng[222][222];

int dfn[222],low[222],index=1;
bool insta[222];
int sta[222],stasz=0;
vector<vi> cir;

void tarjan(int x,int pre){
	dfn[x]=low[x]=index++;
	sta[stasz++]=x;insta[x]=1;
	FOR(i,0,n)if(g[x][i]){
		int to=i;
		if(to!=pre){
			if(!dfn[to]){
				tarjan(to,x);
				low[x]=min(low[x],low[to]);
			}
			else {
				low[x]=min(low[x],dfn[to]);
			}
		}
	}
	if(dfn[x]==low[x]){
		vi c;
		while(1) {
			int u=sta[--stasz];
			insta[u]=0;
			//MINE STARTS HERE
			
			c.push_back(u);
			
			//MINE ENDS
			if(u==x)break;
		}
		cir.push_back(c);
	}
}
int dfs(int x,int pre){
	int ret=0;
	FOR(i,0,n)if(ng[x][i]&&i!=pre){
		Umax(ret,dfs(i,x));
	}
	return ret+1;
}

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>n;
	FOR(i,0,n){
		string s;
		cin>>s;
		FOR(j,0,n)ng[i][j]=g[i][j]=s[j]-'0';
	}
	FOR(i,0,n)if(!dfn[i])tarjan(i,-1);
	FOR(tot,0,cir.size()){
		vi c=cir[tot];
		if(c.size()>1&&c.size()%2){
			cout<<-1<<endl;
			return 0;
		}
		FOR(i,1,c.size()/2){
			FOR(j,0,n){
				ng[c.size()-i][j]|=g[i][j];
				ng[i][j]=0;
				ng[j][c.size()-i]|=g[j][i];
				ng[j][i]=0;
			}
		}
	}
//	FOR(i,0,n)Tall(ng[i],n);
//	return 0;
	int ans=0;
	FOR(i,0,n){
		Umax(ans,dfs(i,-1));
	}
	Tone(ans)
	return 0;
}


Compiler output:
a.cc:74:23: error: 'int index' redeclared as different kind of entity
   74 | int dfn[222],low[222],index=1;
      |                       ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:3:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void tarjan(int, int)':
a.cc:80:28: error: no post-increment operator for type
   80 |         dfn[x]=low[x]=index++;
      |                            ^~