【Codeforces Beta Round #88 C】Cycle
【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的更多相关文章
- 【Codeforces Beta Round #45 D】Permutations
[题目链接]:http://codeforces.com/problemset/problem/48/D [题意] 给你n个数字; 然后让你确定,这n个数字是否能由若干个(1..x)的排列连在一起打乱 ...
- Codeforces Beta Round #88 C. Cycle —— DFS(找环)
题目链接:http://codeforces.com/problemset/problem/117/C C. Cycle time limit per test 2.5 seconds memory ...
- 【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[ ...
- 【Codeforces Global Round 1 C】Meaningless Operations
[链接] 我是链接,点我呀:) [题意] 给你一个a 让你从1..a-1的范围中选择一个b 使得gcd(a^b,a&b)的值最大 [题解] 显然如果a的二进制中有0的话. 那么我们就让选择的b ...
- 【 Codeforces Global Round 1 B】Tape
[链接] 我是链接,点我呀:) [题意] x轴上有m个连续的点,从1标号到m. 其中有n个点是特殊点. 让你用k段区间将这n个点覆盖. 要求区间的总长度最小. [题解] 一开始假设我们需要n个胶带(即 ...
- 【Codeforces Global Round 1 A】Parity
[链接] 我是链接,点我呀:) [题意] 给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数 [题解] 模拟一下转换的过程,加乘的时候都记得对2取余就好 [代码] im ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- 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]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
随机推荐
- GA来源分析
网页中广告素材分为:文字,图片和FLASH三种.针对这三种素材,2种有无参数的情况,新旧版GA收集到的结果为: 提醒:FLASH素材如果不加参数收集不到来源: 具体GA参数如下: 可参考:https: ...
- mui.min.js:7 Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load
mui框架做的微信公众号网页,在上传数据的时候报了这个错,async: true,//将false改为true就可以了 https://blog.csdn.net/liuzp111/article/d ...
- 【Java架构:基础技术】一篇文章搞掂:Spring Boot
本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文是对<Spring Boot 实战第4版>的总结,大家也可以去仔细研读该书 注意,书中使用的Spring Boot ...
- (转)图文详解MyEclipse中新建Maven webapp项目的步骤
转:https://blog.csdn.net/ClementAD/article/details/46592557 MyEclipse中创建新的Maven项目(webapp目录结构)过程如下: ...
- 74、Salesforce的String的format方法
String placehodler = 'Hello {0} , {1} is cool!'; List<String> fillers = new String[]{'Jason',' ...
- spring mvc 初始
今天带领大家开始第一天的spring mvc学习 首先我们要下载maven然后配置IDE 然后选择new 新建项目 然后选择maven,然后选择maven的webapp 然后创建springmvc ...
- Excel2016怎么批量删除空白行 如何删除空白行
我们在编辑Excel文档的时候,如果表格中有大量的空白行,这时我们怎么样把它们批量删除呢?下面我们就一起来看看操作的方法吧. 工具/原料 Excel2016 方法/步骤 首先在电脑上打 ...
- Tomcat 配置安装
1 下载和安装Tomcat服务器 Tomcat官方站点:http://jakarta.apache.org 下载Tomcat安装程序包:http://tomcat.apache.org/ 启动和测试T ...
- <读书笔记>《JS DOM编程艺术》
2016/03/04 12:00 第一二章:JS的简史以及基本语法 1.P11 2.variable 3.P13 等于 4.P13 5.P14 转义字符 6.关联数组不是一个好习惯 7.P18 ...
- HDU 1261 字串数(排列组合)
字串数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...