题意:给出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. zzulioj--1719--小胖的疑惑(整数划分+dp打表)

    1719: 小胖的疑惑 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 108  Solved: 51 SubmitStatusWeb Board De ...

  2. hihoCoder 1403 后缀数组 重复旋律

    思路: 后缀数组 第一次写 留个模板吧 先求出后缀数组,问题转换为询问height数组中连续k-1个数的最小值的最大值,单调队列扫描一遍即可.-yousiki 手懒用得STL //By SiriusR ...

  3. MySQL日期数据类型和时间类型使用总结

    转自: http://blog.chinaunix.net/space.php?uid=11327712&do=blog&id=32416 MySQL 日期类型:日期格式.所占存储空间 ...

  4. ZOJ 3321 Circle【并查集】

    解题思路:给定n个点,m条边,判断是否构成一个环 注意到构成一个环,所有点的度数为2,即一个点只有两条边与之相连,再有就是判断合并之后这n个点是否在同一个连通块 Circle Time Limit: ...

  5. Python 批量处理特定格式文件

    #批量对文件夹下的'.mat'进行处理 def file_name(file_dir,suff): L=[] for root, dirs, files in os.walk(file_dir): f ...

  6. Dapper基础知识三

    在下刚毕业工作,之前实习有用到Dapper?这几天新项目想用上Dapper,在下比较菜鸟,这块只是个人对Dapper的一种总结. Dapper,当项目在开发的时候,在没有必要使用依赖注入的时候,如何做 ...

  7. There is no 'root'@'%' registered解决

      把别人机器上的MYSQL中的一个数据库导出来,生成了一个.sql的文件   在我的机器上导入这个.sql文件之后,在数据库连接时出现了如下错误:   “There is no 'root'@'%' ...

  8. jQuery 完整 ajax示例

    $(function(){ //请求参数 var list = {}; // $.ajax({ //请求方式 type : "POST", //请求的媒体类型 contentTyp ...

  9. C实现JAVA类似ArrayList的静态链接库

    文件结构: ArrayList.h:头文件 ArrayList.c:实现头文件中的功能 ArrayListTest.c:测试 ArrayList.h 头文件的基本框架: #ifndef _ARRAYL ...

  10. worldcount

    码云项目地址 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning 计划 20 20 Estimate 估计这个任务需要多少时间 60 70 Development 开发 ...