#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;
for(int i=1;i<=n;++i)//枚举起点
ans=max(ans,bfs(i));//找长度最长的最短路
printf("%d",ans);
}

Atcoder Grand Contest 039B(思维,BFS)的更多相关文章

  1. AtCoder Grand Contest 019 B - Reverse and Compare【思维】

    AtCoder Grand Contest 019 B - Reverse and Compare 题意:给定字符串,可以选定任意i.j且i<=j(当然i==j时没啥卵用),然后翻转i到j的字符 ...

  2. Atcoder Grand Contest 024 E - Sequence Growing Hard(dp+思维)

    题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序 ...

  3. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  4. AtCoder Grand Contest 005

    AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...

  5. AtCoder Grand Contest 014

    AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中 ...

  6. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  7. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  8. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  9. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

随机推荐

  1. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>

    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1, ...

  2. xhr 的 onpregress 监听上传数据的 已上传 和 总大小

    var fd=new FormData(); $('.mwd_uppingzheng_btna_ok').on('click',function () { // 数组转 str var strarr= ...

  3. sqli-libs(29(jspstudy)-31关)

    Less_29 Less-29: 需要用到jspstudy跟phpstudy   搭建jspstudy: sqli-labs-master文件夹下面还有tomcat文件,这才是真正的关卡,里面的jsp ...

  4. Python学习(七)——匿名函数、map函数、filter函数、reduce函数与其他内置函数

    匿名函数 lambda x: x + 1 # lambda:定义匿名函数的关键字 # x:形参 # x+1:程序处理逻辑 fun = lambda x: x + 1 print(fun(5)) #6 ...

  5. nginx.conf nginx反向代理配置文件

    nginx反向代理配置文件 nginx.conf proxy_default.conf proxy.conf vhost/*.conf upstream/*.conf cache/*.conf ngi ...

  6. 【C语言】创建一个函数,利用该函数将两个字符串连接起来

    代码: #include<stdio.h> ], ]) { int i, j; ; c[i] != '\0'; i++); ; d[j] != '\0'; j++) { c[i++] = ...

  7. 每天进步一点点------时序分析基础与时钟约束实例(四)IO口时序(Input Delay /output Delay)

    1.1  概述 在高速系统中FPGA时序约束不止包括内部时钟约束,还应包括完整的IO时序约束和时序例外约束才能实现PCB板级的时序收敛.因此,FPGA时序约束中IO口时序约束也是一个重点.只有约束正确 ...

  8. SpringBoot踩坑记(HTTP 400 错误)

    HTTP 400 错误 复现错误 ajax请求后台数据时有时会报 HTTP 400 错误 - 请求无效 (Bad request);出现这个请求无效报错说明请求没有进入到后台服务里:原因:1)前端提交 ...

  9. Bug搬运工-CSCvm33229:Environment summary not available on COS APs

    还是关于温度的问题, Environment summary not available on COS APs CSCvm33229   Description Symptom:From WLC CL ...

  10. finally语句块一定会被执行吗

    finally语句块一定会被执行吗? 答案: 不一定 1. 发生异常的代码必须在try 代码块中,才有可能被执行 public class MyTest { public static void ma ...