【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. Ceph BlueStore与FileStore:利用Micron NVMe SSD进行性能比较

    https://www.micron.com/about/blog/2018/may/ceph-bluestore-vs-filestoreblock-performance-comparison-w ...

  2. 集合类不安全之ArrayList

    1. 不安全的ArrayList 大家都知道ArrayList线程不安全,怎么个不安全法呢?上代码: public class ContainerNotSafeDemo { public static ...

  3. KEIL Code RO-data RW-data ZI-data 【转】

    来自:http://jinyong314.blog.163.com/blog/static/30165742201052225415901/ 字节 8位半字 16位字   32位 Code, RO-d ...

  4. 72、salesforce call RESTful 的方式

    通过Chrome的Postman 来call salesforce的restful api https://login.salesforce.com/services/oauth2/token?gra ...

  5. 53、tensorflow基本操作

    import tensorflow as tf import numpy as np x_data = np.float32(np.random.rand(2,100)) print(x_data) ...

  6. Python模块学习之xlrd 读取Excel时传入formatting_info=True报错:NotImplementedError: formatting_info=True not yet implemented

    问题:xlrd读取Excel时传入 formatting_info=True 报错 之前我们使用读取xls文件的时候都是使用的xlrd库,但是这个库只能操作 .xls格式,对于后来的 .xlsx的版本 ...

  7. upc组队赛3 Chaarshanbegaan at Cafebazaar

    Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...

  8. charles使用教程

    概述 Charles是目前最强大的http调试工具,在界面和功能上远胜于Fiddler,同时是全平台支持.是收费软件,可以试用15分钟,下面提供了破解方法.   安装破解 https://www.cn ...

  9. PAT甲级——A1146 TopologicalOrder【25】

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...

  10. camunda任务的一些简单操作

    public class ZccTaskService { TaskService taskService; @Before public void init(){ ProcessEngineConf ...