【Link】:http://codeforces.com/problemset/problem/117/C

【Description】



问你一张图里面有没有一个三元环,有的话就输出。

【Solution】



O(N2)写个图的遍历就行;

主程序里的for循环,是防止多个连通块.



【NumberOf WA】



0



【Reviw】

【Code】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 5000; int n,v[N+10];
char s[N+10][N+10]; bool dfs(int x,int fa){
v[x] = 1;
rep1(i,1,n)
if (s[x][i]-'0'){
if (i!=fa && (s[i][fa]-'0')){
oi(x),oc,oi(i),oc,oi(fa),puts("");
return true;
}
if (!v[i])
if (dfs(i,x)) return true;
}
return false;
} int main(){
//Open();
//Close();
ri(n);
rep1(i,1,n) rs(s[i]); rep1(i,1,n)
if (!v[i])
if (dfs(i,i)) return 0;
puts("-1");
return 0;
}

【Codeforces Beta Round #88 C】Cycle的更多相关文章

  1. 【Codeforces Beta Round #45 D】Permutations

    [题目链接]:http://codeforces.com/problemset/problem/48/D [题意] 给你n个数字; 然后让你确定,这n个数字是否能由若干个(1..x)的排列连在一起打乱 ...

  2. Codeforces Beta Round #88 C. Cycle —— DFS(找环)

    题目链接:http://codeforces.com/problemset/problem/117/C C. Cycle time limit per test 2.5 seconds memory ...

  3. 【Codeforces Global Round 1 E】Magic Stones

    [链接] 我是链接,点我呀:) [题意] 你可以把c[i]改成c[i+1]+c[i-1]-c[i] (2<=i<=n-1) 问你能不能把每一个c[i]都换成对应的t[i]; [题解] d[ ...

  4. 【Codeforces Global Round 1 C】Meaningless Operations

    [链接] 我是链接,点我呀:) [题意] 给你一个a 让你从1..a-1的范围中选择一个b 使得gcd(a^b,a&b)的值最大 [题解] 显然如果a的二进制中有0的话. 那么我们就让选择的b ...

  5. 【 Codeforces Global Round 1 B】Tape

    [链接] 我是链接,点我呀:) [题意] x轴上有m个连续的点,从1标号到m. 其中有n个点是特殊点. 让你用k段区间将这n个点覆盖. 要求区间的总长度最小. [题解] 一开始假设我们需要n个胶带(即 ...

  6. 【Codeforces Global Round 1 A】Parity

    [链接] 我是链接,点我呀:) [题意] 给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数 [题解] 模拟一下转换的过程,加乘的时候都记得对2取余就好 [代码] im ...

  7. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  8. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  9. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

随机推荐

  1. MaxCompute问答整理之10月

    本文是基于本人对MaxCompute产品的学习进度,再结合开发者社区里面的一些问题,进而整理成文.希望对大家有所帮助. 问题一.DataStudio中是否可以通过shell节点调取MaxCompute ...

  2. java web项目的https配置

    1.进入到jdk下的bin目录 keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/tomcat.keystore -validity ...

  3. Spring MVC rest接收json中文格式数据显示乱码

    1.解决方法其中之一 在web.xml下添加配置: <!-- 编码配置 --> <filter> <filter-name>CharacterEncodingFil ...

  4. 52、saleforce 第一篇

    View the Schema 1.点击setup 2.在QuickFind and Search中输入Schema Builder 先点击clear all 去除所有现实的UML,然后选择Line_ ...

  5. CentOS7.5 yum 安装与配置MySQL5.7.24

    安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:https://dev.mysql.com/downloads/rep ...

  6. NetworkComms V3 序列化器之Protobuf.net和 JSONSerializer

    NetworkComms v3版本中,默认使用的是protobuf.net序列化器. 即当您没有指定序列化的时候,系统自动使用默认的protobuf.net序列化器. 当然我们也可以自己指定序列化器 ...

  7. Windows操作系统架构

    用户态 用户态有四类组件,这四类组件都是以进程形式存在的,也就是说,它们都有自己的进程地址空间(其实就是一套页表). 1. System Support Processes 这些是固化的进程,也就是说 ...

  8. 运维 06 vim与程序员

    vim与程序员   所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在. 但是目前我们使用比较多的是 vim 编辑器. vim 具有程序编辑的能力,可以主动的以 ...

  9. js的内部特性--属性

    使用方法:通过调用Object.defineProperty(对象,"对象属性",{}进行的操作}) 当对一个对象的属性的属性类型中vlue设置为一个值时,则这个对象的这个属性的值 ...

  10. jmeter Thread Groups的顺序执行与并行执行

    本期目标: 理解Thread Groups的顺序执行与并行执行 控制因子:Run Thread Groups consecutively(i.e.one at time) 预期结论: 1.勾选 Run ...