ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

hdu-1704 Rank

2019-10-21 21:53:35  阅读:323  来源: 互联网

标签:hdu 1704 int winner two Rank lcy between ask


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).
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.

OJ-ID:
hdu-1704

author:
Caution_X

date of submission:
20191017

tags:
dfs

description modelling:
n个人,m场比赛,输出有多少种选择(a,b)使得不知道a,b谁胜谁负

major steps to solve it:
(1). dfs每一个人的比赛,将所有的间接战胜表示出来(间接战胜:a->b,b->c   =>  a->c)
(2). 遍历所有人的比赛,得出答案

AC code:

#include <cstdio>
#include <cstring>
int n;
int vis[501][501];
void dfs(int x,int y)
{
    for(int i=1;i<=n;i++)
        if(vis[y][i])
        {
            vis[x][i]=1;
            dfs(x,i);
        }
}
int main()
{
   // freopen("a.txt","r",stdin);
   int t,m,a,b;
   scanf("%d",&t);
   while(t--)
   {
       memset(vis,0,sizeof(vis));
       scanf("%d%d",&n,&m);
       for(int i=0;i<m;i++)
       {
           scanf("%d%d",&a,&b);
           vis[a][b]=1;
       }
       for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            if(vis[i][j])
            {
                dfs(i,j);
            }
        int ans=0;
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++)
            if(!vis[i][j]&&!vis[j][i]) ans++;
        printf("%d\n",ans);
   }
   return 0;
}

 

标签:hdu,1704,int,winner,two,Rank,lcy,between,ask
来源: https://www.cnblogs.com/cautx/p/11716475.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有