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. Kubernetes中资源配额管理

    设置资源请求数量 创建Pod的时候,可以为每个容器指定资源消耗的限制.Pod的资源请求限制则是Pod中所有容器请求资源的总和. apiVersion: v1 kind: Pod metadata: n ...

  2. SharePoint每日小贴士Web部件

    SharePoint每日小贴士Web部件 项目描写叙述         此Web部件从指定SP自己定义列表或一个选定的 RSS源选择一个随机项目.并显示一张图片.标题和一个Tip.         适 ...

  3. 00、Word Count

    1.开发环境 1.eclipse-jee-neon-3 2.scala-ide:http://download.scala-ide.org/sdk/lithium/e46/scala212/stabl ...

  4. Linux压力测试工具stress的参数详解

    为了测试服务器的负载情况,可以使用stress这个压力测试工具,可以在环境上验证测试下. stress安装 sudo yum install -y epel-release sudo yum inst ...

  5. C# System.IO.FileStream

    为文件提供 Stream,既支持同步读写操作,也支持异步读写操作. using System; using System.IO; using System.Text; class Test { pub ...

  6. 一步步教你轻松学主成分分析PCA降维算法

    一步步教你轻松学主成分分析PCA降维算法 (白宁超 2018年10月22日10:14:18) 摘要:主成分分析(英语:Principal components analysis,PCA)是一种分析.简 ...

  7. 机器人关节空间轨迹规划--S型速度规划

    关节空间 VS 操作空间 关节空间与操作空间轨迹规划流程图如下(上标$i$和$f$分别代表起始位置initial和目标位置final): 在关节空间内进行轨迹规划有如下优点: 在线运算量更小,即无需进 ...

  8. xhr是什么文件类型?

    xhr:XMLHttpRequest在后台与服务器交换数据,这意味着可以在不加载整个网页的情况下,对网页某部分的内容进行更新. 是Ajax的一种用法,而Ajax并不是一门语言,只是一种不需要加载整个网 ...

  9. go-ehtereum编译:

    git clone https://github.com/ethereum/go-ethereum.git cd go-ethereum && git checkout make ge ...

  10. CentOS 7.X 安全手记

    一.安装云锁 1.报错 Install Selinux Policy Module:yunsuo_install/install: line 371: checkmodule: command not ...