hdu 1704 Rank (floyd闭包)
Rank
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1630 Accepted Submission(s): 627
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).
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.
3 3
1 2
1 3
2 3
3 2
1 2
2 3
4 2
1 2
3 4
0
4
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.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; int a[][];
int t,n,m; void floyd(){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(a[j][i]==){continue;}
for(int k=;k<=n;k++){
a[j][k]=a[j][k]||a[j][i]&a[i][k];
}
}
}
} int main()
{
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
int t1,t2;
int sum=;
memset(a,,sizeof(a));
for(int i=;i<m;i++){
scanf("%d %d",&t1,&t2);
a[t1][t2]=;
}
floyd();
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(a[i][j]!=){
sum++;
}
}
}
printf("%d\n",(n*n-n)/-sum);
}
return ;
}
hdu 1704 Rank (floyd闭包)的更多相关文章
- HDU 1704 Rank
Rank Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 17046 ...
- hdu - 1704 Rank(简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1704 遇到标记过的就dfs,把隐含的标记,最后计数需要注意. #include <cstdio> # ...
- HDU 1704 Rank【传递闭包】
解题思路:给出n个选手,m场比赛,问不能判断胜负的询问最多有多少种 用传递闭包即可 但是如果直接用3重循环会超时 在判断d[i][j]=d[i][k]||d[k][j]是否连通的时候 可以加一个if语 ...
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 1704 (Floyd 传递闭包)
Rank Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Rank HDU - 1704 【传递闭包水题】
there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellen ...
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1869 (Floyd)
http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory ...
随机推荐
- pygame-KidsCanCode系列jumpy-part11-角色动画(下)
接上节继续,上节并没有处理向左走.向右走的动画效果,这节补上,看似很简单,但是有一些细节还是要注意: def jump(self): hits = pg.sprite.spritecollide(se ...
- Linux之清理linux内存cache
转自:https://www.cnblogs.com/madsnotes/articles/5740495.html 频繁的文件访问会导致系统的Cache使用量大增.例如:在使用grep从很多文件中搜 ...
- idea不显示gradle的视图解决办法
选择build tool.找到gradle→Runner,把委托给IDE构建勾选,然后重新导入一次就好了.
- let's encrypt申请
let's encrypt申请 https://keelii.com/2016/06/12/free-https-cert-lets-encrypt-apply-install/ https://ww ...
- 使用AShot进行网页全页截图
import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.Chrom ...
- 【放松一下】北美小游戏排行榜TOP10——“点击英雄”
大家平时工作都比較忙,在这里推荐一款游戏让大家放松一下.让你体验到指数爆炸般挣钱的快感. 北美小游戏排行榜TOP10--"点击英雄" 简要说明: 游戏能够挂机,关闭电脑.游戏也会自 ...
- 人人网框架导入uidGenerator的ID生成方式
人人网框架导入uidGenerator的ID生成方式 2019-03-11 LIUREN SpringBoot2.0 uidGenerator SpringBoot2.0 uidGener ...
- 在 CentOS 7上Virtualbox+phpVirtualBox完整虚拟化环境部署
一.phpVirtualBox简介 VirtualBox是一套为不同操作系统而设的 x86 虚拟化产品.它是一个机器/硬件的虚拟化产品,功能上与 VMware Server.Parallel ...
- 用分离、附加的方式实现sql server数据库的备份和还原
一.数据库分离.附加的说明 SQL Server提供了"分离/附加"数据库."备份/还原"数据库.复制数据库等多种数据库的备份和恢复方法.这里介绍一种学习中常用 ...
- mysql alter 添加索引
1.添加主键索引 ALTER TABLE `table_name` ADD PRIMARY KEY (`column`) 2.添加唯一索引 ALTER TABLE `table_name` ADD U ...