HDU 1704 Rank (关系闭包)
2012-12-05 17:15
309 查看
Rank
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 805 Accepted Submission(s):
279
[align=left]Problem Description[/align]
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).
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, output a integer
which represent the max possible number of queries that you can't
tell lcy.
[align=left]Sample Input[/align]
3 3 3 1 2 1
3 2 3 3 2 1 2 2 3 4 2 1 2 3 4
[align=left]Sample Output[/align]
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.
[align=left]Source[/align]
2007省赛集训队练习赛(1)
[align=left]Recommend[/align]
lcy
关闭闭包 floyd算法
代码:
#include<stdio.h>
#include<string.h>
#define MAXN 501
int map[MAXN][MAXN],n;
void floyd()
{
int
i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
if(map[i][k])
{
for(j=1;j<=n;j++)
map[i][j]=map[i][j]||map[i][k]&&map[k][j];
}
}
int main()
{
int
i,j,T,m,a,b,ans;
scanf("%d",&T);
while(T--)
{
memset(map,0,sizeof(map));
scanf("%d%d",&n,&m);
while(m--)
{
scanf("%d%d",&a,&b);
map[a][b]=1;
}
floyd();
ans=0;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(!(map[i][j]||map[j][i]))
ans++;
printf("%d\n",ans);
}
return
0;
}
相关文章推荐
- HDU 1718 Rank
- (HDU)1213 How Many Tables
- hdu 1427 速算24点
- Hdu 2457 DNA repair (字符串_AC自…
- hdu&nbsp;1010
- HDU:2046骨牌铺方格 解题报告
- HDU: 2015 偶数求和
- HDU:2067 小兔的棋盘
- hdu 1466 计算直线的交点数 第四专…
- HDU 1029 Ignatius and the Prince…
- HDU 1102 Constructing Roads
- HDU 1533 Going Home (KM算法)
- hdu 3125 Slash
- hdu 2084 数塔
- hdu 1704 rank 传递闭包
- HDU 2115 I Love This Game
- HDU 1859 最小长方形
- HDU 1283 最简单的计算机
- hdu 1434 幸福列车
- HDU 3901 Wildcard AC主动机通配符…