码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1704 Rank

时间:2014-09-11 22:16:02      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   java   ar   for   

Rank

Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 1704
64-bit integer IO format: %I64d      Java class name: Main
 
 
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
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.

Source

 
解题:求有多少组关系没法确定。无相图传递闭包。
 
bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define pii pair<int,int>
15 #define INF 0x3f3f3f3f
16 using namespace std;
17 const int maxn = 510;
18 int n,m;
19 bool mp[maxn][maxn];
20 void Floyd(){
21     for(int k = 1; k <= n; k++){
22         for(int i = 1; i <= n; i++){
23             for(int j = 1; mp[i][k]&&j <= n; j++)
24                 mp[i][j] |= mp[i][k]&mp[k][j];
25         }
26     }
27 }
28 int main() {
29     int t,u,v,ans;
30     scanf("%d",&t);
31     while(t--){
32         scanf("%d %d",&n,&m);
33         memset(mp,false,sizeof(mp));
34         for(int i = 0; i < m; i++){
35             scanf("%d %d",&u,&v);
36             mp[u][v] = true;
37         }
38         Floyd();
39         ans = 0;
40         for(int i = 1; i <= n; i++){
41             for(int j = i+1; j <= n; j++)
42                 if(mp[i][j] == 0 && mp[j][i] == 0) ans++;
43         }
44         printf("%d\n",ans);
45     }
46     return 0;
47 }
View Code

 

HDU 1704 Rank

标签:style   blog   http   color   io   os   java   ar   for   

原文地址:http://www.cnblogs.com/crackpotisback/p/3967306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!