hdu 1704 (Floyd 传递闭包)
Rank
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1622 Accepted Submission(s):
625
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).
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.
the max possible number of queries that you can't tell lcy.
3 3
1 2
1 3
2 3
3 2
1 2
2 3
4 2
1 2
3 4
0
4
#include<bits/stdc++.h>
using namespace std;
int e[][];
int main()
{
int t,n,m,i,j,k;
cin>>t;
while(t--){int s=,a,b;
cin>>n>>m;memset(e,,sizeof(e));
for(i=;i<=m;++i){
cin>>a>>b;
e[a][b]=;
e[b][a]=-;
}
for(k=;k<=n;++k)
for(i=;i<=n;++i)
if(e[i][k]==){
for(j=;j<=n;++j)
if(e[k][j]==) e[i][j]=,e[j][i]=-; }
for(i=;i<=n;++i)
for(j=+i;j<=n;++j){
if(!e[i][j]) s++;
} cout<<s<<endl;
}
return;
}
hdu 1704 (Floyd 传递闭包)的更多相关文章
- Rank HDU - 1704 【传递闭包水题】
there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellen ...
- UVA 247 电话圈 (floyd传递闭包 + dfs输出连通分量的点)
题意:输出所有的环: 思路:数据比较小,用三层循环的floyd传递闭包(即两条路通为1,不通为0,如果在一个环中,环中的所有点能互相连通),输出路径用dfs,递归还没有出现过的点(vis),输出并递归 ...
- UVA 753 UNIX 插头(EK网络流+Floyd传递闭包)
UNIX 插头 紫书P374 [题目链接]UNIX 插头 [题目类型]EK网络流+Floyd传递闭包 &题解: 看了书之后有那么一点懂了,但当看了刘汝佳代码后就完全明白了,感觉他代码写的好牛逼 ...
- UVA 247 电话圈(Floyd传递闭包+输出连通分量)
电话圈 紫书P365 [题目链接]电话圈 [题目类型]Floyd传递闭包+输出连通分量 &题解: 原来floyd还可以这么用,再配合连通分量,简直牛逼. 我发现其实求联通分量也不难,就是for ...
- HDU 5036 Explosion (传递闭包+bitset优化)
<题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...
- POJ 3660 Cow ContestCow(Floyd传递闭包)题解
题意:给出m个关系,问你能确定机头牛的排名 思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名. 代码: #include<cstd ...
- nyoj 211——Cow Contest——————【floyd传递闭包】
Cow Contest 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1.. ...
- POJ3660:Cow Contest(Floyd传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16941 Accepted: 9447 题目链接 ...
- POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】
Treasure Exploration Time Limit:6000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- 第一次使用crontab linux选择编辑器问题
第一次使用crontab linux选择编辑器问题 第一次使用crontab 时,会出现no crontab for root - using an empty one“Select a editor ...
- 代码静态扫描工具sonar
一.SonarQube整体介绍 SonarQube为静态代码检查工具,采用B/S架构,帮助检查代码缺陷,改善代码质量,提高开发速度,通过插件形式,可以支持Java.C.C++.JavaScripe等等 ...
- echart知识点、常用图形
原文地址:https://www.cnblogs.com/kewenxin/p/9338272.html 本文是自己在项目中需要运用到的echarts图形进行整理,都有完整的代码.echarts原型, ...
- 20145106 《Java程序设计》第10周学习总结
教材学习内容总结 什么是计算机网络? 计算机网络,是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享 ...
- IDEA Java开发常用插件
这里只是推荐一下好用的插件,具体的使用方法就不一一详细介绍了. JRebel for IntelliJ 一款热部署插件,只要不是修改了项目的配置文件,用它都可以实现热部署.收费的,破解比较麻烦.不过功 ...
- 【文件readonly异常】异常退出编译文件,再次进入提示readonly
1.对于同一个文件如果上次已经打开,而未关闭的情况下,又打开该文件进行编辑时,会出现如下提醒: 这是由于已经打开但未闭关的文件,会在其目录下出现一个.swp的文件,由于是属于隐藏文件,可以用命令l. ...
- 【自定义IK词典】Elasticsearch之中文分词器插件es-ik的自定义词库
Elasticsearch之中文分词器插件es-ik 针对一些特殊的词语在分词的时候也需要能够识别 有人会问,那么,例如: 如果我想根据自己的本家姓氏来查询,如zhouls,姓氏“周”. 如 ...
- 51nod 1183 编辑距离
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1183. 题意不再赘述. 分析:大概和LCS差不多的吧 但是我用LCS ...
- CMD与AMD区别
- java 如果仅输出一位和要输出多位格式的输出问题,利用boolean值.
package com.ykmimi.testtest; /** * 第七周第二题,来自网络 */ import java.util.Scanner; public class NumberPerfe ...