【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 ...
随机推荐
- boot、cloud
最近在学习Spring Boot也整理了一些文章,有需要的可以参考一下 https://www.zhihu.com/question/39483566 Spring Cloud是一系列框架的有序集合. ...
- Linux系统之-TCP-IP链路层
一.基本 网络层协议的数据单元是 IP 数据报 ,而数据链路层的工作就是把网络层交下来的 IP 数据报 封装为 帧(frame)发送到链路上,以及把接收到的帧中的数据取出并上交给网络层. 为达到这一目 ...
- Python3 tkinter 界面布局(转自https://blog.csdn.net/junjun5156/article/details/72510927)
所谓布局,就是指控制窗体容器中各个控件(组件)的位置关系.tkinter 共有三种几何布局管理器,分别是:pack布局,grid布局,place布局. pack布局 使用 pack布局,将向容器中添加 ...
- Windows 8.1 PLSQL_32连接到RHEL6.1 Oracle10gr2_64
目录 目录 系统环境 连接Oracle Server 系统环境 操作系统 Windows 8.1 RHEL6.1 软件 Oracle10gr2 PL/SQL instantclient-basic-w ...
- PAT甲级——A1145 HashingAverageSearchTime【25】
The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...
- 开发效率优化之Git分布式版本控制系统(一)
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680本篇文章将先从Git分布式版本控制系统来阐述开发效率优化 一,企业 ...
- 利用TKinter模块创建GUI窗口
# -*- coding: utf-8 -*- from Tkinter import * root = Tk() # 80x80代表了初始化时主窗口的大小,0,0代表了初始化时窗口所在的位置 ...
- redis 入门之哈希
hset 将哈希表 hash 中域 field 的值设置为 value .如果给定的哈希表并不存在, 那么一个新的哈希表将被创建并执行 HSET 操作.如果域 field 已经存在于哈希表中, 那么它 ...
- kmp与扩展kmp模板
kmp 1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include & ...
- SpringMVC学习(4):数据绑定1 @RequestParam
在系列(3)中我们介绍了请求是如何映射到一个action上的,下一步当然是如何获取到请求中的数据,这就引出了本篇所要讲的内容-数据绑定. 首先看一下都有哪些绑定数据的注解: 1.@RequestPar ...