题意:给出n个人,如果a喜欢b,那么b一定不喜欢a,如果b不喜欢a,那么a一定喜欢b

就是这n个点里面的任意两点都存在一条单向的边, 所以如果这n个点不能构成拓扑序列的话,就一定成环了,成环的话就一定能够找到一个三元环

所以只需要判断能不能构成拓扑序列

另外,tle了一晚上是因为用了cin------55555555555555

以后少用cin了-----

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; vector<int> g[maxn];
int in[maxn],ans[maxn];
char str[maxn];
int n; void toposort(){
queue<int> q;
for(int i=;i<n;i++)
if(in[i]==) q.push(i); int cnt=;
while(!q.empty()){
int x=q.front();q.pop();
ans[++cnt]=x; for(int j=;j<g[x].size();j++){
int m=g[x][j];
in[m]--;
if(in[m]==) q.push(m);
}
}
if(cnt==n) printf("No\n");
else printf("Yes\n");
} int main(){
int T;
cin>>T;
for(int t=;t<=T;t++){
cin>>n; memset(in,,sizeof(in)); for(int i=;i<n;i++){
g[i].clear();
scanf("%s",str); for(int j=;j<n;j++){
if(str[j]=='') g[i].push_back(j),in[j]++;
}
}
printf("Case #%d: ",t);
toposort();
}
return ;
}

现在想想,觉得这道题目好悲伤啊-------------- 唉

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. 题解报告:hdu 2647 Reward(拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...

  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://www.cnblogs.com/newpanderking ...

  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(拓扑判环)

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

  7. hdu 4324 Triangle LOVE

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

  8. hdu 5098 双队列拓扑排序

    http://acm.hdu.edu.cn/showproblem.php?pid=5098 软件在安装之后需要重启才能发挥作用,现在给你一堆软件(有的需要重启有的不需要)以及安装这个软件之前需要哪些 ...

  9. HDU 5811 Colosseo(拓扑排序+单调DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5811 [题目大意] 给出 一张单向图,现在将其划分成了两个部分,问划分之后的点是否分别满足按照一定 ...

  10. HDU 2647 Reward(拓扑排序+判断环+分层)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题目大意:要给n个人发工资,告诉你m个关系,给出m行每行a b,表示b的工资小于a的工资,最低工 ...

随机推荐

  1. UVA - 10229 Modular Fibonacci 矩阵快速幂

                                 Modular Fibonacci The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 3 ...

  2. WIN7使用VisualSVN建立SVN服务器

    使用SVN开发十分的方便,这样就不用每次都拷贝粘贴来备份了,网上看到一篇给自己的windows电脑安装SVN服务器的使用非常方便. 1.下载安装文件(服务器端和客户端) 服务器端采用VisualSVN ...

  3. Another app is currently holding the yum lock; waiting for it to exit…

    yum被锁定无法使用,错误信息截图如下:解决方法:rm -rf /var/run/yum.pid 来强行解除锁定,然后你的yum就可以运行了

  4. KafkaZookeeper2-ZookeeperClient

    介绍 ZookeeperClient 是 kafka 新写的客户端,它允许用户流水线式(并行)访问 zookeeper. 为什么放弃了 zkClient? zkClient 是一个第三方的客户端. 它 ...

  5. c# iTextSharp导出PDF

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Th ...

  6. 关于 jsp java servlet 中文汉字乱码的解决方法

    在servlet类中的get,post最前面加上 req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding(&quo ...

  7. JavaScript学习——DOM对象

    1.DOM操作 Document:整个html文件都称之为一个document文档 Element:所有的标签都是Element元素 Attribute:标签里面的属性 Text:标签中间夹着的内容为 ...

  8. java中,length,length(),size()区别

    length——数组的属性: length()——String的方法: size()——集合的方法:

  9. java后台生成图片二维码

    controller: /** * 获取登录的验证码 * @param request * @param response */ public void getLoginCode(HttpSessio ...

  10. HTTP——学习笔记(8)

    HTTP中的一些协议内容会限制某些网站的功能使用 比如,Facebook这类的社交网站,需要实时地观察到海量用户公开发布的内容,而HTTP中的以下标准就会成为瓶颈: 一条连接上只可发送一个请求 请求只 ...