Triangle LOVE(拓扑排序)】的更多相关文章

Triangle LOVE Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Submission(s) : 49   Accepted Submission(s) : 30 Problem Description Recently, scientists find that there is love between any of two people. For exam…
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 wor…
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3566    Accepted Submission(s): 1395 Problem Description Recently, scientists find that there is love between any of two people. For…
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1707    Accepted Submission(s): 729 Problem Description Recently, scientists find that there is love between any of two people. For…
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2683    Accepted Submission(s): 1084 Problem Description Recently, scientists find that there is love between any of two people. Fo…
因为题目说了,两个人之间总有一个人喜欢另一个人,而且不会有两个人互相喜欢.所以只要所给的图中有一个环,那么一定存在一个三元环. 所以用拓扑排序判断一下图中是否有环就行了. #include <cstdio> #include <cstring> + ; char G[maxn][maxn]; int c[maxn]; int n; bool dfs(int u) { c[u] = -; ; v < n; v++) ') { ) return false; if(!c[v] &…
题目 /***************************参考自****************************/ http://www.cnblogs.com/newpanderking/archive/2012/10/16/2726757.html 上有详细注解,我是看了之后写的,我的代码有一咪咪的改动 //这是一道典型的拓扑排序的题,刚开始时没有理解,//上网查了好多关于拓扑排序的知识才明白,//就是针对一个顶点活动网(Activity On Vertex network),简…
这是一道最简单的拓扑排序题,好久没看这个算法了! 有点生疏了! 后附上百度的资料; #include<stdio.h> #include<string.h> int in[5000]; char map[3000][3000]; int n; int panduan() { int i,j,k; for(i=0;i<n;i++) for(j=0;j<n;j++) if(map[i][j]=='1') in[j]++; for(i=0;i<n;i++) { j=0;…
https://vjudge.net/problem/HDU-4324 题意 每组数据一个n表示n个人,接下n*n的矩阵表示这些人之间的关系,输入一定满足若A不喜欢B则B一定喜欢A,且不会出现A和B相互喜欢的情况,问你这些人中是否存在三角恋. 分析 就是求是否存在三元环.判断图是否存在环,可以使用拓扑排序,排序失败则有环.那么如何判断存在的环是三元环呢? 假设现在存在n元环,在环上有这样相邻的三个元素x-->y-->z.如果是z-->x,那么存在三元环:否则,必存在x-->z,那此…
题目传送门 题意:判三角恋(三元环).如果A喜欢B,那么B一定不喜欢A,任意两人一定有关系连接 分析:正解应该是拓扑排序判环,如果有环,一定是三元环,证明. DFS:从任意一点开始搜索,搜索过的点标记,否则超时.看是否存在两点路程只差等于2,如果存在,则说明有上述的三角环.其他做法. 收获:DFS搜索一定要用vis数组啊,否则很容易超时的 代码(拓扑排序): /************************************************ * Author :Running_T…