there are N ACMers in HDU team.
ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellent ACMers to attend the contest. There have been M matches since the last few days(No two ACMers will meet each other at two matches, means between two ACMers there will be at most one match). lcy also asks"Who is the winner between A and B?" But sometimes you can't answer lcy's query, for example, there are 3 people, named A, B, C.and 1 match was held between A and B, in the match A is the winner, then if lcy asks "Who is the winner between A and B", of course you can answer "A", but if lcy ask "Who is the winner between A and C", you can't tell him the answer.
As lcy's assistant, you want to know how many queries at most you can't tell lcy(ask A B, and ask B A is the same; and lcy won't ask the same question twice).

InputThe input contains multiple test cases.
The first line has one integer,represent the number of test cases.
Each case first contains two integers N and M(N , M <= 500), N is the number of ACMers in HDU team, and M is the number of matchs have been held.The following M lines, each line means a match and it contains two integers A and B, means A wins the match between A and B.And we define that if A wins B, and B wins C, then A wins C.OutputFor each test case, output a integer which represent the max possible number of queries that you can't tell lcy.Sample Input

3
3 3
1 2
1 3
2 3
3 2
1 2
2 3
4 2
1 2
3 4

Sample Output

0
0
4

Hint

in the case3, if lcy ask (1 3 or 3 1) (1 4 or 4 1) (2 3 or 3 2) (2 4 or 4 2), then you can't tell him who is the winner.

题意:有一场比赛,对于n个选手给出m场比赛的结果,结果有传递性,问有多少对选手不能判断他们之间的胜负关系。

思路 :floyd求解传递闭包

AC代码:

 #include<bits/stdc++.h>

 using namespace std;
#define maxn 766
int e[maxn][maxn];
int main(){
int _;
cin>>_;
while(_--){
int n,m;
scanf("%d%d",&n,&m);
int x,y;
while(m--){
//cin>>x>>y;
scanf("%d%d",&x,&y);
e[x][y]=;
}
for(int k=;k<=n;k++)
for(int i=;i<=n;i++){
if(!e[i][k])
continue;
for(int j=;j<=n;j++)
if(e[i][k]&&e[k][j])
e[i][j]=;
} int ans=;
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
if(!e[i][j]&&!e[j][i])
ans++;
printf("%d\n",ans);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
e[i][j]=;
}
}

Rank HDU - 1704 【传递闭包水题】的更多相关文章

  1. hdu 5210 delete 水题

    Delete Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...

  2. hdu 1251 (Trie水题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  3. 变形课 HDU - 1181 【floyd传递闭包水题】

    呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个 ...

  4. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  5. HDU 4493 Tutor 水题的收获。。

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...

  6. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  7. hdu 4493 Tutor 水题

    Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...

  8. hdu 5495 LCS 水题

    LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...

  9. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

随机推荐

  1. C++ 日志库 boost::log 以及 glog 的对比

    日志能方便地诊断程序原因.统计程序运行数据,是大型软件系统必不可少的组件之一.本文将从设计上和功能上对比 C++ 语言常见的两款日志库: boost::log 和 google-glog . 设计 b ...

  2. VMware的下载与安装

    VMware的下载与安装 一.虚拟机的下载 1.进入VMware官网,点击左侧导航栏中的下载,再点击图中标记的Workstation Pro,如下图所示. 2.根据操作系统选择合适的产品,在这里以Wi ...

  3. 利用Python进行数据分析_Pandas_数据清理、转换、合并、重塑

    1 合并数据集 pandas.merge pandas.merge(left, right, how='inner', on=None, left_on=None, right_on=None, le ...

  4. Python之系统编程笔记

    概念 命令行工具. Shell 脚本.  系统管理 系统模块 sys   提供一组功能映射Python运行时的操作系统 os    提供跨平台可移植的操作系统编程接口   os.path 提供文件及目 ...

  5. 怎样给回调函数绑定this

    在三种绑定this的方法中, Function.prototype.call() 和 Function.prototye.apply() 都是会立即执行该函数的, 但回调函数是不能立即执行的, 它只是 ...

  6. iOS 9.0中UIAlertController的用法。

    1.我为什么要写这篇博客记录它? 答:因为 UIAlertView和UIActionSheet 被划线了 苹果不推荐我们使用这两个类了,也不再进行维护和更新,为了以后方便使用我来记录一下.如图所示 正 ...

  7. 图像处理库GPUImage简单使用

    一.介绍 GPUImage是一个基于OpenGL ES 2.0的开源的图像处理库,作者是Brad Larson.GPUImage将OpenGL ES封装为简洁的Objective-C或Swift接口, ...

  8. c#开启线程池超出索引

    这样写会超出索引,foreach好像不会超出,原因可能是开启线程池需要时间,成功开启之后,一次循环已经结束,这个没有验证. 以下这个做法是不对的,我也是看网上的贴这样写,结果是少执行了一个.推荐大家还 ...

  9. Mycat详解及配置读写分离(Centos7)

    目录 一.理论概述 二.环境 三.部署 一.理论概述 原理简述 参考文档 MyCAT主要是通过对SQL的拦截,然后经过一定规则的分片解析.路由分析.读写分离分析.缓存分析等,然后将SQL发给后端真实的 ...

  10. python 并发编程-- 多进程

    一 multiprocessing 模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程 ...