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 ;
}

最新文章

  1. 基于shell脚本比较数字加减乘除
  2. ICollection
  3. .NET对象与Windows句柄(一):句柄的基本概念
  4. 用css画出对话框
  5. 网络流量监控工具iftop
  6. JavaScript 异常
  7. Centos6的VSFTP服务器配置使用教程
  8. 项目管理工具 Redmine 安装试用手记
  9. 把luasocket集成到c++中
  10. callLater
  11. Hive中常用的参数配置
  12. Navicat Premium 12激活教程
  13. Object.defineProperty方法
  14. VS下个人认为比较实用的插件
  15. angular2.0学习笔记4.npm常用指令记录及angular语法
  16. Linux 下创建 sftp 用户并限定目录
  17. MySQL基础(一)
  18. nginx实战七
  19. ThinkPHP自定义成功界面、失败界面、异常界面
  20. pdo封装2

热门文章

  1. 搜狗拼音输入法 V9.1.0.2589 最新去广告精简优化版
  2. 使用linux kernel代码编译perf工具
  3. Java全栈程序员之07:IDEA中使用MAVEN构架生产级的Web项目
  4. [Javascript] Multiply Two Arrays over a Function in JavaScript
  5. edis更新的正确方法
  6. Web Workers 简介
  7. GDAL指定自定义的金字塔目录
  8. 【C++】C++中的流
  9. sql中的left join以及on、where关键字的区别
  10. hive SQL 静态分区和 动态分区