Rank

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 1704
64-bit integer IO format: %I64d      Java class name: Main

 
 
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

 
解题:求有多少组关系没法确定。无向图传递闭包。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int n,m;
bool mp[maxn][maxn];
void Floyd(){
for(int k = ; k <= n; k++){
for(int i = ; i <= n; i++){
for(int j = ; mp[i][k]&&j <= n; j++)
mp[i][j] |= mp[i][k]&mp[k][j];
}
}
}
int main() {
int t,u,v,ans;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
memset(mp,false,sizeof(mp));
for(int i = ; i < m; i++){
scanf("%d %d",&u,&v);
mp[u][v] = true;
}
Floyd();
ans = ;
for(int i = ; i <= n; i++){
for(int j = i+; j <= n; j++)
if(mp[i][j] == && mp[j][i] == ) ans++;
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. MongoDB数据库的操作,增删改查
  2. 基于Socket客户端局域网或广域网内共享同一短信猫收发短信的开发解决方案
  3. C语言 自动修改文件名小程序
  4. ios广告
  5. 友善p35屏
  6. Http的请求对象
  7. 那些在学习iOS开发前就应该知道的事(part 1)
  8. jQuery的插入
  9. CMAKE的用法
  10. c# 根据自定义Attribute排序
  11. C#第十二天
  12. Mock API是如何在开发中发光发热的?
  13. iou与giou对比
  14. wx.navigateBack(OBJECT)怎么携带参数呢?
  15. [js]面向对象1
  16. mysql: 查看某库表大小
  17. * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]’
  18. HTML5和CSS3阶段,我是如何学习的?
  19. Tkinter制作简单的python编辑器
  20. Spring+Hibernate+struts2+JPA 注解+跨域//完成手机端点击加载更多 下拉加载更多

热门文章

  1. Extjs 3 控制Grid某行某列不可编辑
  2. WCF学习笔记——契约不能少了set
  3. 学习笔记——DISTINCT
  4. linux下dd命令详解【转】
  5. bzoj 4318 OSU! —— 期望DP
  6. Coursera Algorithms week2 基础排序 练习测验: Permutation
  7. 安装DotnetCore-Vue项目模板
  8. npm搭建React项目
  9. HTML中javascript使用dom获取dom节点范例
  10. vue中的config配置