Triangle LOVE

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 3603    Accepted Submission(s): 1416

Problem Description
Recently, scientists find that there is love between any of two people. For example, between A and B, if A don’t love B, then B must love A, vice versa. And there is no possibility that two people love each other, what a crazy world!

Now, scientists want to know whether or not there is a “Triangle Love” among N people. “Triangle Love” means that among any three people (A,B and C) , A loves B, B loves C and C loves A.

  Your problem is writing a program to read the relationship among N people firstly, and return whether or not there is a “Triangle Love”.
 
Input
The first line contains a single integer t (1 <= t <= 15), the number of test cases.

For each case, the first line contains one integer N (0 < N <= 2000).

In the next N lines contain the adjacency matrix A of the relationship (without spaces). Ai,j = 1 means i-th people loves j-th people, otherwise Ai,j = 0.

It is guaranteed that the given relationship is a tournament, that is, Ai,i= 0, Ai,j ≠ Aj,i(1<=i, j<=n,i≠j).
 
Output
For each case, output the case number as shown and then print “Yes”, if there is a “Triangle Love” among these N people, otherwise print “No”.

Take the sample output for more details.
 
Sample Input
2
5
00100
10000
01001
11101
11000
5
01111
00000
01000
01100
01110
 
Sample Output
Case #1: Yes Case #2: No 输入一个矩阵,假设a[i][j]==1,意思是i喜欢j。问存不存在一个三角恋关系,
既拓扑排序判环,,要深入理解拓扑排序的原理
2015,8,14
#include<stdio.h>
#include<string.h>
#define M 2100
char mp[M][M];
int du[M];
int n,cas;
void topo(){
int ok=0,i,k;
for(int i=1;i<=n;i++){
for(k=1;k<=n;k++)
if(du[k]==0) //z找到入度为0的点
break;
if(k==n+1){//假设不存在入度为0的点。那么就是一定存在环 ,就有三角恋
ok=1;
break;
}else{
du[k]--;//删除这个点
for(int j=1;j<=n;j++){
if(mp[k][j]=='1'&&du[j]!=0)
du[j]--;
}
}
}
if(ok) printf("Case #%d: Yes\n",cas++);
else printf("Case #%d: No\n",cas++);
}
int main(){
int i,j,t;
cas=1;
scanf("%d",&t);
while(t--){
memset(du,0,sizeof(du));
scanf("%d",&n);
for(i=1;i<=n;i++){//依照凝视的输入会超时
//getchar();
scanf("%s",mp[i]+1);;
for(j=1;j<=n;j++){
// scanf("%c",&mp[i][j]);
if(mp[i][j]=='1')
du[j]++;
}
}
topo();
}
return 0;
}

hdu 4324 Triangle LOVE(拓扑判环)的更多相关文章

  1. HDU 4324 Triangle LOVE 拓扑排序

    Problem Description Recently, scientists find that there is love between any of two people. For exam ...

  2. E. Andrew and Taxi(二分+拓扑判环)

    题目链接:http://codeforces.com/contest/1100/problem/E 题目大意:给你n和m,n代表有n个城市,m代表有m条边,然后m行输入三个数,起点,终点,花费.,每一 ...

  3. HDU 4324 Triangle LOVE (拓扑排序)

    Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  4. hdu 4324 Triangle LOVE

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4324 Triangle LOVE Description Recently, scientists f ...

  5. HDU - 4324 Triangle LOVE(拓扑排序)

    https://vjudge.net/problem/HDU-4324 题意 每组数据一个n表示n个人,接下n*n的矩阵表示这些人之间的关系,输入一定满足若A不喜欢B则B一定喜欢A,且不会出现A和B相 ...

  6. HDU 4324 Triangle LOVE【拓扑排序】

    题意:给出n个人,如果a喜欢b,那么b一定不喜欢a,如果b不喜欢a,那么a一定喜欢b 就是这n个点里面的任意两点都存在一条单向的边, 所以如果这n个点不能构成拓扑序列的话,就一定成环了,成环的话就一定 ...

  7. hdu 4324 Triangle LOVE(拓扑排序,基础)

    题目 /***************************参考自****************************/ http://www.cnblogs.com/newpanderking ...

  8. Coloring Edges 【拓扑判环】

    题目链接:https://vjudge.net/contest/330119#problem/A 题目大意: 1.给出一张有向图,给该图涂色,要求同一个环里的边不可以全部都为同一种颜色.问最少需要多少 ...

  9. 【建图+拓扑判环】BZOJ3953: [WF2013]Self-Assembly

    Description 自动化学制造(Automatic Chemical Manufacturing,简称ACM)正在对一个叫自组装(self-assembly)的过程进行实验.在这个过程中,有着天 ...

随机推荐

  1. ActiveMQ学习笔记(3)----JMS的可靠性机制

    1. 消息接收确认 JMS消息只有在被确认之后,才认为已经被成功的消费了,消息成功消费通常包含三个阶段:客户接收消息,客户处理消息和消息被确认. 在事务性会话中,当一个事务被提交的时候,确认自动发生. ...

  2. dedecmsV5.7自定义图片字段调用方法

    正常情况下,在列表页(也就是 {dede:list}标签)调用附加的图片类型字段则会出现Fatal error: Call to a member function GetInnerText() on ...

  3. webpack 操作

    依赖安装 :  全局安装webpack : sudo npm install webpack -g 本地安装webpack : npm install webpack —save-dev  需要注意的 ...

  4. [UVa10188]Automated Judge Script

    题目大意:叫你写一个判断答案的系统. 解题思路:模拟即可.AC条件为,答案条数相等,所有字符相等.PE条件为,答案条数可能不等,所有数字字符相等.其他为WA. UVa现在的C++已经不支持gets了, ...

  5. BZOJ 1444 [JSOI2009]有趣的游戏 (Trie图/AC自动机+矩阵求逆)

    题目大意:给你$N$个长度相等且互不相同的模式串,现在有一个字符串生成器会不断生成字符,其中每个字符出现的概率是$p_{i}/q_{i}$,当生成器生成的字符串包含了某个模式串,则拥有该模式串的玩家胜 ...

  6. k8s日志收集配置

    容器日志样例 172.101.32.1 - - [03/Jun/2019:17:14:10 +0800] "POST /ajaxVideoQueues!queryAllUser.action ...

  7. 解决wps的ppt演示不能打开的问题libbz2.so.1.0

      安装 wps-office-10.1.0.5707-1.a21.x86_64 无法打开ppt 其他正常

  8. Java8 Lamdba表达式 002

    本篇将讲述lamdba表达式的排序,本例包括一个Player对象的集合[稍后定义],通过每一个player的分数高低对列表的player进行排序.类定义001例如以下 public class Sor ...

  9. HTML5 canvas炫酷棱镜效果的幻灯片特效

    这是一款效果很炫酷华丽的HTML5 canvas带棱镜效果的幻灯片特效. 这个特效在每个幻灯片的前面放置一个图形.并将图形制作为三棱镜效果.它底下的幻灯片图片会被"折射"到棱镜上面 ...

  10. JNI之——&#39;cl&#39; 不是内部或外部命令,也不是可执行的程序或批处理文件

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46604315 问题的出现:     今天卸载了VS2010,重装vs2008后.发 ...