Rank

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1630    Accepted Submission(s): 627

Problem Description
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).
 
Input
The 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.
 
Output
For 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.

 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1703 1700 1701 1706 1705 
 #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闭包)的更多相关文章

  1. HDU 1704 Rank

    Rank Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 17046 ...

  2. hdu - 1704 Rank(简单dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1704 遇到标记过的就dfs,把隐含的标记,最后计数需要注意. #include <cstdio> # ...

  3. HDU 1704 Rank【传递闭包】

    解题思路:给出n个选手,m场比赛,问不能判断胜负的询问最多有多少种 用传递闭包即可 但是如果直接用3重循环会超时 在判断d[i][j]=d[i][k]||d[k][j]是否连通的时候 可以加一个if语 ...

  4. ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线

    hdu 1811 Rank of Tetris Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  5. hdu 1704 (Floyd 传递闭包)

    Rank Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. Rank HDU - 1704 【传递闭包水题】

    there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellen ...

  7. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  8. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  9. hdu 1869 (Floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. 介绍三款串口监控工具:Device Monitoring Studio,portmon,Comspy

    在开发上位机下位机通讯程序时,有一个好的监控工具会事半功倍.特在网上找了几款串口监控软件,作了简单对比: 一.Device Monitoring Studio 网址:http://www.hhdsof ...

  2. jeffy-vim-v3.1.tar.gz

    下载链接: https://files.cnblogs.com/files/pengdonglin137/jeffy-vim-v3.1.tar.gz 1. 使用sublimemonokai配色 2. ...

  3. enctype和Content-type有什么关系

    enctype和Content-type有什么关系 当我们使用form表单上传文件时post请求的时候,需要在form表单中添加enctype="multipart/form-data&qu ...

  4. Docker 安装和基础用法

    理解Docker(1):Docker 安装和基础用法 本系列文章将介绍Docker的有关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 ...

  5. shell中打印带有时间的日志的命令(转)

    echo "`date "+%Y-%m-%d %H:%M:%S"` | [logadm -on@`date "+%Y%m%d%H%M%S"`] &qu ...

  6. 正确清理binlog日志

    摘要: MySQL中的binlog日志记录了数据库中数据的变动,便于对数据的基于时间点和基于位置的恢复,但是binlog也会日渐增大,占用很大的磁盘空间,因此,要对binlog使用正确安全的方法清理掉 ...

  7. mongodb连接配置实践

    之前百度,google了很多,发现并没有介绍mongodb生产环境如何配置的文章, 当时想参考下都不行, 所以写篇文章,大家可以一块讨论下. 1. MongoClientOptions中的连接池配置: ...

  8. Jquery DataTables 获取表格数据及行数据

    注意table变量是 1.jQuery DataTables 行号获取 $("#example tbody tr").on("click", function( ...

  9. BizTalk RosettaNet 开发笔记

    RNIF BAM Tracking Error  解决办法:  503: Service Unavailable   解决办法:IIS 应用程序池运行账户用户名或密码错误,用户名不能是doma ...

  10. How do I learn machine learning?

    https://www.quora.com/How-do-I-learn-machine-learning-1?redirected_qid=6578644   How Can I Learn X? ...