Rank

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1622    Accepted Submission(s):
625

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

 
给出n人的m对关系图,a b表示a能战胜b,战胜有传递性,即(a,b)(b,c)--->(a,c)
mdzz一开始bfs跑一波,双向建图,后来发现不服对,假如(1,5)(1,6),5-6是没关系的,但由于双向建图反而有了关系,所以WA。
不如(a,b)时,e[a][b]=1表示a战胜b,e[b][a]=-1,表示b输给了a,接着Floyd跑一波,最后统计。
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int e[][];
  4. int main()
  5. {
  6. int t,n,m,i,j,k;
  7. cin>>t;
  8. while(t--){int s=,a,b;
  9. cin>>n>>m;memset(e,,sizeof(e));
  10. for(i=;i<=m;++i){
  11. cin>>a>>b;
  12. e[a][b]=;
  13. e[b][a]=-;
  14. }
  15. for(k=;k<=n;++k)
  16. for(i=;i<=n;++i)
  17. if(e[i][k]==){
  18. for(j=;j<=n;++j)
  19. if(e[k][j]==) e[i][j]=,e[j][i]=-;
  20. }
  21. for(i=;i<=n;++i)
  22. for(j=+i;j<=n;++j){
  23. if(!e[i][j]) s++;
  24. } cout<<s<<endl;
  25. }
  26. return;
  27. }

hdu 1704 (Floyd 传递闭包)的更多相关文章

  1. Rank HDU - 1704 【传递闭包水题】

    there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellen ...

  2. UVA 247 电话圈 (floyd传递闭包 + dfs输出连通分量的点)

    题意:输出所有的环: 思路:数据比较小,用三层循环的floyd传递闭包(即两条路通为1,不通为0,如果在一个环中,环中的所有点能互相连通),输出路径用dfs,递归还没有出现过的点(vis),输出并递归 ...

  3. UVA 753 UNIX 插头(EK网络流+Floyd传递闭包)

    UNIX 插头 紫书P374 [题目链接]UNIX 插头 [题目类型]EK网络流+Floyd传递闭包 &题解: 看了书之后有那么一点懂了,但当看了刘汝佳代码后就完全明白了,感觉他代码写的好牛逼 ...

  4. UVA 247 电话圈(Floyd传递闭包+输出连通分量)

    电话圈 紫书P365 [题目链接]电话圈 [题目类型]Floyd传递闭包+输出连通分量 &题解: 原来floyd还可以这么用,再配合连通分量,简直牛逼. 我发现其实求联通分量也不难,就是for ...

  5. HDU 5036 Explosion (传递闭包+bitset优化)

    <题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...

  6. POJ 3660 Cow ContestCow(Floyd传递闭包)题解

    题意:给出m个关系,问你能确定机头牛的排名 思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名. 代码: #include<cstd ...

  7. nyoj 211——Cow Contest——————【floyd传递闭包】

    Cow Contest 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1.. ...

  8. POJ3660:Cow Contest(Floyd传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16941   Accepted: 9447 题目链接 ...

  9. POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

    Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. mysql8.0无法给用户授权或提示You are not allowed to create a user with GRANT的问题

    提示意思是不能用grant创建用户,mysql8.0以前的版本可以使用grant在授权的时候隐式的创建用户,8.0以后已经不支持,所以必须先创建用户,然后再授权,命令如下: mysql> CRE ...

  2. Python入门之Python引用模块和查找模块路径

    #这篇文章主要介绍了Python引用模块和Python查找模块路径的相关资料,需要的朋友可以参考下 模块间相互独立相互引用是任何一种编程语言的基础能力.对于“模块”这个词在各种编程语言中或许是不同的, ...

  3. 修改Nginx配置文件来隐藏index.php

    找到你要修改的域名对应nginx配置文件(vhost下),添加如下代码 location / { if (!-e $request_filename) { rewrite ^(.*)$ /index. ...

  4. php打印负载函数、Linux awk打印负载

    php的sys_getloadavg sys_getloadavt()可以获得系统负载情况.该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1.5和15分钟内的平均负载. 与其让服务器因 ...

  5. Python3 ChromeDriver与Chrome版本映射表(更新至v2.43)

    Python3 ChromeDriver与Chrome版本映射表(更新至v2.43) ChromeDriver下载链接:http://chromedriver.storage.googleapis.c ...

  6. python监控端口脚本[jkport2.0.py]

    #!/usr/bin/env python #!coding=utf-8 import os import time import sys import smtplib from email.mime ...

  7. Notepad++7.5.4 设置主题,使用插件

    首先官网下载 Notepad++7.5.4 默认英文转换成中文 下面设置主题: 设置-->语言格式设置 选择主题Obsidian,字体选择等宽字体Consolas,大小为11,选择全局字体,使用 ...

  8. 【jdk源码分析】java.lang.Appendable

    1.概述 public interface Appendable 能够被添加 char 序列和值的对象.如果某个类的实例打算接收取自 Formatter 的格式化输出,那么该类必须实现 Appenda ...

  9. The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 解决方法

    项目忽然出现 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Pat ...

  10. hdu 1573 X问题 两两可能不互质的中国剩余定理

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Desc ...