HDU 1704 Rank
Rank
This problem will be judged on HDU. Original ID: 1704
64-bit integer IO format: %I64d Java class name: Main
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 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
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
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 ;
}
HDU 1704 Rank的更多相关文章
- hdu 1704 Rank (floyd闭包)
Rank Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 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 & % ...
- Rank HDU - 1704 【传递闭包水题】
there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellen ...
- hdu 1718 Rank
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1718 Rank Description Jackson wants to know his rank ...
- hdu 1811 Rank of Tetris - 拓扑排序 - 并查集
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
- hdu 1704 (Floyd 传递闭包)
Rank Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- android 添加一个按键键值【转】
本文转载自:http://blog.csdn.net/u012719256/article/details/52526046 1.frameworks/base/data/keyboards/Gene ...
- FFT模板——copied from hzwer
/* Welcome Hacking Wish You High Rating */ #include<iostream> #include<cstdio> #include& ...
- WPF:通过Window.DataContext实现窗口间传值
通过Window.DataContext实现窗口之间的传值,特别是跨窗口控件的联动,具有无可比拟的优势.实现方法如下: 1. MainWindow.xaml,在Window.DataContext中 ...
- Autobiography
Autobiography My name is Donggongdechen. I am ** years old. I was born in XuChang, HeNan province, t ...
- succ
- OC常用的数学函数及宏定义
一.函数 1. 三角函数 double sin (double);正弦 double cos (double);余弦 double tan (double);正切 2 .反三角函数 double as ...
- 线性预测与Levinson-Durbin算法实现
在学习信号处理的时候,线性预测是一个比较难理解的知识点,为了加快很多朋友的理解,这里给出Levinson-Durbin算法的线性预测实现和一个测试Demo,Demo中很明确的把输入信号.预测信号.预测 ...
- ROS-URDF-活动关节
前言:介绍活动关节,并使机器人活动起来. 参考自:http://wiki.ros.org/urdf/Tutorials/Building%20a%20Movable%20Robot%20Model%2 ...
- Kali linux 2016.2(Rolling)之 Nessus安装及Plugins Download Fail 解决方法
最近,因科研需要,学习Nessus. Nessus是一款优秀的漏洞扫描软件,在其v6 HOME版本中在线更新漏洞插件不成功,采用离线更新,成功地更新了插件,在此将更新方法进行分享. 1.Nessus软 ...
- spring整合redis客户端及缓存接口设计
一.写在前面 缓存作为系统性能优化的一大杀手锏,几乎在每个系统或多或少的用到缓存.有的使用本地内存作为缓存,有的使用本地硬盘作为缓存,有的使用缓存服务器.但是无论使用哪种缓存,接口中的方法都是差不多. ...