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. Reactor Cooling ZOJ - 2314 上下界网络流

    Code: #include<cstdio> #include<algorithm> #include<vector> #include<queue> ...

  2. react-native之文件上传下载

    目录 文件上传 1.文件选择 2.文件上传 1.FormData对象包装 2.上传示例 文件下载 最近react-native项目上需要做文件上传下载的功能,由于才接触react-native不久,好 ...

  3. CF587F Duff is Mad(AC自动机+树状数组+分块)

    考虑两一个暴力 1 因为询问\([a,b]\)可以拆成\([1,b]\)-\([1,a-1]\)所以把询问离线,然后就是求\([1,x]\)中被\(S_i\)包含的串的数量.考虑当\([1,x-1]- ...

  4. jq 遍历 元素

    $("#spec").find("div.gods-spe").each(function(i,n){ var child = $(this).children ...

  5. es-for-Laravel: Composer 包安装, Laravel 最简单的方式操作 Elasticsearch

    composer 安装:composer require ethansmart/es-for-laravel github 地址:https://github.com/roancsu/es-for-l ...

  6. vue-quill-editor-upload : 实现vue-quill-editor上传图片到服务器

    vue-quill-editor-upload git: https://github.com/NextBoy/vu... A plug-in for uploading images to your ...

  7. 紫书 例题8-13 UVa 11093 (反证法)

    这道题发现一个性质就解决了 如果以i为起点, 然后一直加油耗油, 到p这个地方要去p+1的时候没油了, 那么i, i+1, --一直到p, 如果以这些点 为起点, 肯定也走不完. 为什么呢? 用反证法 ...

  8. 题解 洛谷 P1580 【yyy loves Easter_Egg I】

    一言不合上代码: #include<cstdio> #include<cstring> ],bz[],dmz[]; int maohao,xf,ls,sss,lll,xxf,x ...

  9. 【BZOJ 1059】[ZJOI2007]矩阵游戏

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 最后要求对于所有的i,a[i][i]=1 那么,如果第i行的第j列为1. 就说明我们可以把这个第i行换到第j行. 因为这样的话,a[ ...

  10. Oracle中set serveroutput on介绍

    定义 set serveroutpu on是使oracle可以使用自带的输出方法 dbms_output.put_line('XX'); 使用范围 使用于PL/SQL COMMAND WINDOW,S ...