Rank HDU - 1704 【传递闭包水题】
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).
InputThe 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.OutputFor 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.
题意:有一场比赛,对于n个选手给出m场比赛的结果,结果有传递性,问有多少对选手不能判断他们之间的胜负关系。
思路 :floyd求解传递闭包
AC代码:
#include<bits/stdc++.h> using namespace std;
#define maxn 766
int e[maxn][maxn];
int main(){
int _;
cin>>_;
while(_--){
int n,m;
scanf("%d%d",&n,&m);
int x,y;
while(m--){
//cin>>x>>y;
scanf("%d%d",&x,&y);
e[x][y]=;
}
for(int k=;k<=n;k++)
for(int i=;i<=n;i++){
if(!e[i][k])
continue;
for(int j=;j<=n;j++)
if(e[i][k]&&e[k][j])
e[i][j]=;
} int ans=;
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
if(!e[i][j]&&!e[j][i])
ans++;
printf("%d\n",ans);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
e[i][j]=;
}
}
Rank HDU - 1704 【传递闭包水题】的更多相关文章
- hdu 5210 delete 水题
Delete Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...
- hdu 1251 (Trie水题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- 变形课 HDU - 1181 【floyd传递闭包水题】
呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个 ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- HDU 4493 Tutor 水题的收获。。
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...
- hdu 4802 GPA 水题
GPA Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...
- hdu 4493 Tutor 水题
Tutor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...
- hdu 5495 LCS 水题
LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
随机推荐
- VS2010 安装boost库
1.下载boost库 boost官网:www.boost.org,目前最新的版本是1.64,直接下载地址:https://dl.bintray.com/boostorg/release/1.64.0/ ...
- python学习-22 字符串格式化
格式化包括:百分号方式和format方式 1.百分号 - %s (%.4s 表示截取了4个字符) 传单个值: 例如: print('i am %s sex boy is ljj'%123) 运 ...
- 模块 os 和 sys
目录 os 模块 sys 模块 os 模块 os 模块是与操作系统交互的一个接口 方法 详解 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir(&quo ...
- 关联安装 mysql ,zabbix , nginx, php
/usr/local/zabbix-3.2.6 /usr/local/php-5.6.3 /usr/local/mysql-5.7.26 安装mysql mv /etc/yum.repos.d/Cen ...
- WUSTOJ 1247: 递增或递减排序(Java)
1247: 递增或递减排序 题目 有n个整数,求它的递增排序序列或递减排序序列.更多内容点击标题. 分析 统一升序排序,输出的时候做区分. 先区分是升序还是降序,调用库函数. 代码 方法1,将 ...
- Centos7安装gitlab11 学习笔记之备份恢复及邮箱配置
一.备份 修改配置文件 vim /etc/gitlab/gitlab.rb 默认路径为 # gitlab_rails['backup_path'] = "/var/opt/gitlab/ba ...
- (五)lucene之特定项搜索和查询表达式
需求:模糊搜索. 前提: 本例中使用lucene 5.3.0 package com.shyroke.lucene; import java.io.File; import java.io.File ...
- WPF 自定义一个控件,当点击按钮是触发到ViewModel(业务逻辑部分)和Xaml路由事件(页面逻辑部分)
#region - 用于绑定ViewModel部分 - public ICommand Command { get { return (ICommand)GetValue(CommandPropert ...
- POJ1988(Cube Stacking)--并查集
题目链接:http://poj.org/problem?id=1988 题意:有n个元素,开始每个元素各自在一个栈中,有两种操作,将含有元素x的栈放在含有y的栈的顶端,合并为一个栈. 第二种操作是询问 ...
- Win10安装PyQt5与Qt Designer
1.直接在cmd中通过pip安装PyQt5 1 pip install pyqt5 会自动下载PyQt5以及sip并安装,因为PyQt5不再提供Qt Designer等工具,所以需要再安装pyqt5- ...