Atcoder Grand Contest 039B (thinking, BFS)

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int col[207],s[207],n;
char ss[207][207];
int bfs(int x){
int l=0,r=0;
for(int i=1;i<=n;i++)
col[i]=0;
s[++r]=x;
col[x]=1;
while(l<r){
x=s[++l];
for(int i=1;i<=n;i++)
if(ss[x][i]-'0'){
if(col[i]==0){
col[i]=col[x]+1;
s[++r]=i;
}
else if(abs(col[i]-col[x])!=1)
return -1;
}
}
return col[s[r]];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int ans=-1;
cin>>n;
for (int I =. 1; I <= n-; I ++)
CIN >> SS [I] + 1'd;
for (int I =. 1; I <= n-; I ++) // Enumeration starting
ans = max (ans, bfs (i)) ; // find the shortest length of the longest of
the printf ( "% D", ANS);
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11627240.html